尝试使用带有自定义conf.d的docker-compose运行nginx时出错

问题描述 投票:0回答:1

我正在尝试设置具有多个容器的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利用自定义配置和模板,而不会遇到这样的问题?

docker nginx docker-compose nginx-config
1个回答
0
投票

问题已解决。

我正在尝试使用Docker上下文在EC2机器上执行此操作。

虽然Docker --context [context]一直是稳定版本的一部分(至少对于MacOS是这样),但[[v06.0-rc2上已添加docker-compose --context [context],因此此刻您需要在其中安装Docker Edge为了使它起作用。

我使用的是set context [context]而不是显式的--context形式,这意味着我实际上是在本地进行部署,但并未意识到这一点。
© www.soinside.com 2019 - 2024. All rights reserved.