将 nginx conf 安装为 docker 卷会导致系统错误 boot2docker

Mounting nginx conf as a docker volume causes system error boot2docker

我正在尝试在 docker 容器中 运行 nginx,同时安装配置和静态 html 文件以供其使用。据我所知,这些东西非常简单,但我一直收到有关目录不是目录的错误消息?

我运行使用最新版本的 Boot2Docker 在我的 Mac 上使用这个示例。

我有以下文件夹结构:

% 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 目录中),如下所示:

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

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

有人知道我遗漏了什么吗?

Mac Boot2Docker 卷问题?

我知道在使用 Boot2Docker 时将卷装载到容器中存在问题(尽管我相信这个问题早已解决)

Mount volume to Docker image on OSX

但我还是按照那里的说明去做了,还是不行

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

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

-v /Users/M/Projects/Docker/nginx-example/nginx.conf:/etc/nginx/nginx.conf:ro 你应该没问题。查看 Docker Volumes Docs

中的示例

此外,pwd 应该在路径中起作用。 shell 在 docker 命令是 运行 之前扩展它,就像数学和内括号一样,内部子命令是 运行 在前。