1

Docker version 19.03.5, build 633a0ea838

Linux xxx 5.0.0-37-generic #40~18.04.1-Ubuntu SMP Thu Nov 14 12:06:39 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

I'm trying to setup an Nginx Proxy with Docker for a multiple wordpress instances on the same machine following this guide: pattonwebz multiple wordpress containers The resulting Dockerfile of the nginx-proxy containers is this:

version: '2'
services:
  nginx:
    image: jwilder/nginx-proxy:alpine 
    container_name: nginx
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - /etc/nginx/conf.d
      - /etc/nginx/vhost.d
      - /usr/share/nginx/html
      - ./certs:/etc/nginx/certs:ro
      - /var/run/docker.sock:/tmp/docker.sock:ro
    environment:
      - ENABLE_IPV6=true

  dockergen:
    image: jwilder/docker-gen
    container_name: dockergen
    command: -notify-sighup nginx -watch /etc/docker-gen/templates/nginx.tmpl /etc/nginx/conf.d/default.conf
    volumes_from:
      - nginx
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro
      - ./nginx.tmpl:/etc/docker-gen/templates/nginx.tmpl:ro

  whoami:
    image: jwilder/whoami
    environment:
      - VIRTUAL_HOST=whoami.local

  nginx-letsencrypt:
    image: jrcs/letsencrypt-nginx-proxy-companion
    environment:
      #ACME_CA_URI:https://acme-staging.api.letsencrypt.org/directory
      - NGINX_DOCKER_GEN_CONTAINER=dockergen
    container_name: nginx-letsencrypt
    volumes_from:
      - nginx
    volumes:
      - ./certs:/etc/nginx/certs:rw
      - /var/run/docker.sock:/var/run/docker.sock:ro

networks:
  default:
    external:
      name: nginx-proxy

I've created the network nginx-proxy but running this command in a clean environment (volumes and containers cleared) I've got the following errror:

whoami_1             | Listening on :8000
nginx                | WARNING: /etc/nginx/dhparam/dhparam.pem was not found. A pre-generated dhparam.pem will be used for now while a new one
nginx                | is being generated in the background.  Once the new dhparam.pem is in place, nginx will be reloaded.
nginx                | Generating DH parameters, 2048 bit long safe prime, generator 2
nginx                | forego     | starting dockergen.1 on port 5000
nginx                | forego     | starting nginx.1 on port 5100
nginx                | dockergen.1 | 2020/01/12 17:57:26 Generated '/etc/nginx/conf.d/default.conf' from 4 containers
nginx                | dockergen.1 | 2020/01/12 17:57:26 Running 'nginx -s reload'
dockergen            | 2020/01/12 17:57:26 Generated '/etc/nginx/conf.d/default.conf' from 4 containers
dockergen            | 2020/01/12 17:57:26 Sending container 'nginx' signal '1'
dockergen            | 2020/01/12 17:57:26 Watching docker events
dockergen            | 2020/01/12 17:57:26 Contents of /etc/nginx/conf.d/default.conf did not change. Skipping notification ''
nginx                | dockergen            | 2020/01/12 17:57:26 Received event die for container f34a91bce20f
nginx exited with code 2
dockergen            | 2020/01/12 17:57:26 Contents of /etc/nginx/conf.d/default.conf did not change. Skipping notification ''
nginx-letsencrypt    | Info: Custom Diffie-Hellman group found, generation skipped.
nginx-letsencrypt    | Reloading nginx docker-gen (using separate container dockergen)...
dockergen            | 2020/01/12 17:57:27 Received signal: hangup
dockergen            | 2020/01/12 17:57:27 Received signal: hangup
nginx-letsencrypt    | Reloading nginx (using separate container f34a91bce20f421d03ef0e1a8190e55d0f592d4c2ef30920bcebaa527db4d60f)...
nginx-letsencrypt    | {"message":"Cannot kill container: f34a91bce20f421d03ef0e1a8190e55d0f592d4c2ef30920bcebaa527db4d60f: Container f34a91bce20f421d03ef0e1a8190e55d0f592d4c2ef30920bcebaa527db4d60f is not running"}
dockergen            | 2020/01/12 17:57:27 Contents of /etc/nginx/conf.d/default.conf did not change. Skipping notification ''
nginx-letsencrypt    | 2020/01/12 17:57:27 Generated '/app/letsencrypt_service_data' from 3 containers
nginx-letsencrypt    | 2020/01/12 17:57:27 Running '/app/signal_le_service'
nginx-letsencrypt    | 2020/01/12 17:57:27 Watching docker events
nginx-letsencrypt    | 2020/01/12 17:57:27 Contents of /app/letsencrypt_service_data did not change. Skipping notification '/app/signal_le_service'
nginx-letsencrypt    | 2020/01/12 17:57:27 Error: nginx-proxy container f34a91bce20f421d03ef0e1a8190e55d0f592d4c2ef30920bcebaa527db4d60f isn't running.
nginx-letsencrypt    | Sleep for 3600s

so nginx exited with code 2 tells me nginx hangup and I'm not able to figure out what is the problem. I tried also to disable the line in the nginx container

 - /var/run/docker.sock:/tmp/docker.sock:ro

but with no luck.

1 Answer 1

0

This might not be the only problem but your setup is wrong. Either you use jwilder/nginx-proxy which contains nginx AND dockergen scripts. Either you want to use your own settled nginx image (built from the official nginx image) and you use as a companion jwilder/dockergen which will create the config files for you. But you don't use both of these images.

This is very well explained in the jwilder/nginx-proxy documentation dealing with separate container setup.

If you look carefully at your log, you will see that the nginx container is starting dockergen followed by the same try from the dockergen container. This is likely not a good idea...

I suggest you take a decision, fix your configuration in either way (single or dual container) then retry and see if you still have issues. I have been running the separate container setup in production and updating it at least monthly for the past three years.

1

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.