将nginx conf作为docker卷加载会导致系统错误boot2docker [英] Mounting nginx conf as a docker volume causes system error boot2docker

查看:231
本文介绍了将nginx conf作为docker卷加载会导致系统错误boot2docker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图在Docker容器中运行nginx,同时安装配置和静态html文件以供服务。非常简单的东西,据我所知,但我不断收到目录不是一个目录的错误?

I'm trying to run nginx within a docker container whilst mounting the configuration and static html files for it to serve up. Very simple stuff as far as I'm aware, but I keep getting an error about the directory not being a directory?

我正在我的Mac上运行这个例子最新版本的Boot2Docker。

I'm running this example on my Mac using the latest version of Boot2Docker.

我有以下文件夹结构:

% tree                 ~/Projects/Docker/nginx-example
.
├── html
│   └── test.html
└── nginx.conf

1 directory, 2 files

nginx.conf 的内容如下:

http {
  server {
    listen *:80; # Listen for incoming connections from any interface on port 80
    server_name ""; # Don't worry if "Host" HTTP Header is empty or not set
    root /usr/share/nginx/html; # serve static files from here
  }
}

我尝试运行容器(从〜/ Projects / Docker / nginx-example 目录中)像这样:

I try to run the container (from within the ~/Projects/Docker/nginx-example directory) like so:

docker run --name nginx-container \
  -v /Users/M/Projects/Docker/nginx-example/html:/usr/share/nginx/html:ro \
  -v /Users/M/Projects/Docker/nginx-example/nginx.conf:/etc/nginx:ro \
  -P -d nginx




最初我尝试过像$ code> -v $(pwd)/ html:/ usr / share / nginx / html:ro 保持命令更短,但是当它不工作时,我以为我会明确的,以防万一有一些时髦的子shell问题,我不知道

Originally I had tried something like -v $(pwd)/html:/usr/share/nginx/html:ro to keep the command shorter, but when it didn't work I thought I'd be explicit just in case there was some funky sub shell issue I wasn't aware of

我得到以下输出

fc41205914098d236893a3b4e20fa89703567c666ec1ff29f123215dfbef7163
Error response from daemon: 
Cannot start container fc41205914098d236893a3b4e20fa89703567c666ec1ff29f123215dfbef7163: 
[8] System error: not a directory

有没有人有任何想法什么我缺少?

Does anyone have any idea of what I'm missing?

我知道有一个问题使用Boot2Docker将容器加载到容器中(尽管我被认为已经解决了这个问题)

I'm aware there is an issue with mounting volumes into containers when using Boot2Docker (although I'm led to believe this has long been resolved)

ie 将音量装载到OSX上的Docker映像

但是,我遵循这些说明,而且仍然没有工作。

But I followed the instructions there regardless, and it still didn't work

推荐答案

p> -v /Users/M/Projects/Docker/nginx-example/nginx.conf:/etc/nginx:ro

您正在尝试将文件挂载到目录中 - 将其更改为:

you are attempting to mount a file to a directory - change that to:

-v / Users / M / Projects / Docker / nginx-example / nginx.conf:/etc/nginx/nginx.conf:ro 你应该没事看看 Docker卷文档中的示例

-v /Users/M/Projects/Docker/nginx-example/nginx.conf:/etc/nginx/nginx.conf:ro and you should be fine. Take a look at the examples in the Docker Volumes Docs

同样, pwd 应该在路径中工作。在运行docker命令之前,shell会扩展它,就像数学和内括号一样,内部子命令首先运行。

As well, pwd should work in the path. The shell expands this before the docker command is run, just like math and inner parenthesis, inner sub-commands are run first.

这篇关于将nginx conf作为docker卷加载会导致系统错误boot2docker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆