docker-compose: 无法指定 nginx 配置
docker-compose: can't specify nginx config
我正在尝试通过 docker-compose 设置一个 nginx 容器。我有一个我想使用的自定义配置。我在与容器共享的卷上提供配置。
nginx:
volumes:
- shared:/shared
image: nginx
ports:
- "8080:80"
- "443:443"
command: /bin/bash -c ./shared/nginx_test.conf
配置文件如下:
daemon off;
http {
server {
location / {
root /shared/data/www;
}
location /images/ {
root /data;
}
}
}
当我执行 docker-compose up 时,配置中的每一行都出现错误,提示未找到命令。例如./shared/nginx_test.conf: line 1: daemon: command not found
、./shared/nginx_test.conf: line 3: http: command not found
等等。
我尝试按照指南 here 进行操作。关于为什么 nginx 找不到命令的任何想法?
您正在尝试 运行 使用 bash -c
的脚本文件,您看到了吗?那不是你想要的。 (错误消息说 ./shared/nginx_test.conf
的内容不被理解,Bash 解释为终端命令。)
您可能想要 运行 类似于 nginx -g daemon off
的命令,并将配置文件附加为参数:
nginx:
# ...
command: nginx -c ./shared/nginx_test.conf -g "daemon off;"
参考文献:
我正在尝试通过 docker-compose 设置一个 nginx 容器。我有一个我想使用的自定义配置。我在与容器共享的卷上提供配置。
nginx:
volumes:
- shared:/shared
image: nginx
ports:
- "8080:80"
- "443:443"
command: /bin/bash -c ./shared/nginx_test.conf
配置文件如下:
daemon off;
http {
server {
location / {
root /shared/data/www;
}
location /images/ {
root /data;
}
}
}
当我执行 docker-compose up 时,配置中的每一行都出现错误,提示未找到命令。例如./shared/nginx_test.conf: line 1: daemon: command not found
、./shared/nginx_test.conf: line 3: http: command not found
等等。
我尝试按照指南 here 进行操作。关于为什么 nginx 找不到命令的任何想法?
您正在尝试 运行 使用 bash -c
的脚本文件,您看到了吗?那不是你想要的。 (错误消息说 ./shared/nginx_test.conf
的内容不被理解,Bash 解释为终端命令。)
您可能想要 运行 类似于 nginx -g daemon off
的命令,并将配置文件附加为参数:
nginx:
# ...
command: nginx -c ./shared/nginx_test.conf -g "daemon off;"
参考文献: