Error trying to run nginx using docker-compose with custom conf.d

22,469

Problem solved.

I was trying to perform this using a docker context onto an EC2 machine.

Whilst Docker --context [context] has been part of the stable version (at least for MacOS) for a while, docker-compose --context [context] was added on v1.26.0-rc2 so at this moment in time you need Docker Edge installed in order to make it work.

I was using set context [context] rather than the explicit --context form which meant I was actually deploying locally but being unaware of it.

Share:
22,469
Manu 'Jimbo' Matute
Author by

Manu 'Jimbo' Matute

Updated on May 25, 2021

Comments

  • Manu 'Jimbo' Matute
    Manu 'Jimbo' Matute about 3 years

    I'm trying to set up a web server with multiple containers - but starting with a simple setup for my reverse proxy.

    My docker-compose.yml looks as follows:

    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
    

    Having nginx-config folder structure like:

    nginx-config
    |- templates
      |-default.conf.template
      |- sites-available
        |- mysite.conf.template
    

    And default.conf.template that looks like:

    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;
    }
    

    However, whenever I run docker-compose --context myremote up it doesn´t work, throwing the following output:

    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
    

    It all generates the right output under nginx-config/conf.d/default.conf at least on my local machine.

    Is there any way I can take advantage of custom config and templates using docker-compose without running into such an issue?