Docker nginx-proxy 在启动时挂起

Docker nginx-proxy 在启动时挂起

Docker 版本 19.03.5,内部版本 633a0ea838

Linux xxx 5.0.0-37-generic #40~18.04.1-Ubuntu SMP 11 月 14 日星期四 12:06:39 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

我正在尝试按照本指南为同一台计算机上的多个 WordPress 实例设置带有 Docker 的 Nginx 代理:pattonwebz 多个 WordPress 容器 nginx-proxy 容器生成的 Dockerfile 如下:

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

我已经创建了网络 nginx-proxy,但在干净的环境中运行此命令(已清除卷和容器),出现以下错误:

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

所以 nginx exited with code 2 告诉我 nginx 挂起,我无法弄清楚问题是什么。我还尝试禁用 nginx 容器中的行

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

但没有运气。

答案1

这可能不是唯一的问题,但您的设置是错误的。您可以使用jwilder/nginx-proxy包含 nginx 和 dockergen 脚本的文件。您要么想使用自己固定的 nginx 映像(从官方 nginx 映像构建),然后将其用作同伴,jwilder/dockergen它将为您创建配置文件。但您不使用这两个图像。

jwilder/nginx-proxy这在处理文档中得到了很好的解释单独的容器设置

如果仔细查看日志,您将看到nginx容器正在启动 dockergen,然后从容器中进行相同的尝试dockergen。这可能不是一个好主意......

我建议您做出决定,以任一方式(单容器或双容器)修复您的配置,然后重试并查看是否仍然存在问题。在过去的三年里,我一直在生产中运行单独的容器设置,并至少每月更新一次。

相关内容