尝试 运行 nginx 使用 docker-compose 与自定义 conf.d 时出错
Error trying to run nginx using docker-compose with custom conf.d
我正在尝试设置具有多个容器的 Web 服务器 - 但从我的反向代理的简单设置开始。
我的docker-compose.yml看起来如下:
version: '3'
services:
reverse-proxy:
container_name: reverse-proxy
hostname: reverse-proxy
image: nginx:latest
ports:
- 80:80
volumes:
- ./nginx-config/conf.d:/etc/nginx/conf.d
- ./html:/usr/share/nginx/html
environment:
- NGINX_PORT=80
- ENV=development
具有 nginx-config 文件夹结构,如:
nginx-config
|- templates
|-default.conf.template
|- sites-available
|- mysite.conf.template
和 default.conf.template 看起来像:
server {
listen ${NGINX_PORT} default_server;
listen [::]:${NGINX_PORT} default_server;
server_name _;
root /usr/share/nginx/html;
charset UTF-8;
error_page 404 /notfound.html;
location = /notfound.html {
allow all;
}
location / {
return 404;
}
access_log off;
log_not_found off;
error_log /var/log/nginx/error.log error;
}
但是,每当我 运行 docker-compose --context myremote up
它不起作用时,抛出以下输出:
reverse-proxy | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
reverse-proxy | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
reverse-proxy | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
reverse-proxy | 10-listen-on-ipv6-by-default.sh: Getting the checksum of /etc/nginx/conf.d/default.conf
reverse-proxy | 10-listen-on-ipv6-by-default.sh: /etc/nginx/conf.d/default.conf differs from the packaged version, exiting
reverse-proxy | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
reverse-proxy | /docker-entrypoint.sh: Configuration complete; ready for start up
至少在我的本地机器上,在 nginx-config/conf.d/default.conf 下,它都会生成正确的输出。
有什么方法可以利用 docker-compose 的自定义配置和模板,而不会 运行 遇到这样的问题?
问题已解决。
我试图在 EC2 机器上使用 docker 上下文来执行此操作。
虽然 Docker --context [context]
已经成为稳定版本的一部分(至少对于 MacOS)有一段时间了,但 docker-compose --context [context]
是在 v1.26.0-rc2 因此此时您需要 Docker 安装 Edge 才能使其正常工作。
我使用的是 set context [context]
而不是明确的 --context
形式,这意味着我实际上是在本地部署但没有意识到这一点。
我正在尝试设置具有多个容器的 Web 服务器 - 但从我的反向代理的简单设置开始。
我的docker-compose.yml看起来如下:
version: '3'
services:
reverse-proxy:
container_name: reverse-proxy
hostname: reverse-proxy
image: nginx:latest
ports:
- 80:80
volumes:
- ./nginx-config/conf.d:/etc/nginx/conf.d
- ./html:/usr/share/nginx/html
environment:
- NGINX_PORT=80
- ENV=development
具有 nginx-config 文件夹结构,如:
nginx-config
|- templates
|-default.conf.template
|- sites-available
|- mysite.conf.template
和 default.conf.template 看起来像:
server {
listen ${NGINX_PORT} default_server;
listen [::]:${NGINX_PORT} default_server;
server_name _;
root /usr/share/nginx/html;
charset UTF-8;
error_page 404 /notfound.html;
location = /notfound.html {
allow all;
}
location / {
return 404;
}
access_log off;
log_not_found off;
error_log /var/log/nginx/error.log error;
}
但是,每当我 运行 docker-compose --context myremote up
它不起作用时,抛出以下输出:
reverse-proxy | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
reverse-proxy | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
reverse-proxy | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
reverse-proxy | 10-listen-on-ipv6-by-default.sh: Getting the checksum of /etc/nginx/conf.d/default.conf
reverse-proxy | 10-listen-on-ipv6-by-default.sh: /etc/nginx/conf.d/default.conf differs from the packaged version, exiting
reverse-proxy | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
reverse-proxy | /docker-entrypoint.sh: Configuration complete; ready for start up
至少在我的本地机器上,在 nginx-config/conf.d/default.conf 下,它都会生成正确的输出。
有什么方法可以利用 docker-compose 的自定义配置和模板,而不会 运行 遇到这样的问题?
问题已解决。
我试图在 EC2 机器上使用 docker 上下文来执行此操作。
虽然 Docker --context [context]
已经成为稳定版本的一部分(至少对于 MacOS)有一段时间了,但 docker-compose --context [context]
是在 v1.26.0-rc2 因此此时您需要 Docker 安装 Edge 才能使其正常工作。
我使用的是 set context [context]
而不是明确的 --context
形式,这意味着我实际上是在本地部署但没有意识到这一点。