Docker-letsencrypt-nginx-proxy-companion: "Error: can't get nginx-proxy container id" when using docker-compose

Created on 5 Sep 2016  路  5Comments  路  Source: nginx-proxy/docker-letsencrypt-nginx-proxy-companion

Hey,

Thanks for the project!

I'm having an issue getting this going with my setup. I'm on Fedora 24, using Docker 1.10.3 and Docker-compose 1.7.1.

I've got a docker-compose.yml file set up like this:

nginx:
  image: jwilder/nginx-proxy
  container_name: nginx
  restart: always
  ports:
    - "80:80"
    - "443:443"
  volumes:
    - "/var/run/docker.sock:/tmp/docker.sock:ro"
    - "./volumes/etc/nginx/vhost.d:/etc/nginx/vhost.d"
    - "./volumes/etc/nginx/certs:/etc/nginx/certs:ro"
    - "./volumes/usr/share/nginx/html:/usr/share/nginx/html"
  security_opt:
    - "label:type:docker_t"

letsencrypt:
  image: jrcs/letsencrypt-nginx-proxy-companion
  restart: always
  volumes_from:
    - nginx
  volumes:
    - "/var/run/docker.sock:/var/run/docker.sock:ro"
    - "./volumes/etc/nginx/certs:/etc/nginx/certs:rw"

I'm getting this output in the logs when I spin up the container:

nginx          | forego     | starting nginx.1 on port 5000
nginx          | forego     | starting dockergen.1 on port 5100
nginx          | dockergen.1 | 2016/09/05 04:54:35 Generated '/etc/nginx/conf.d/default.conf' from 1 containers
nginx          | dockergen.1 | 2016/09/05 04:54:35 Running 'nginx -s reload'
nginx          | dockergen.1 | 2016/09/05 04:54:35 Watching docker events
letsencrypt_1  | Error: can't get nginx-proxy container id !
letsencrypt_1  | Check that you use the --volumes-from option to mount volumes from the nginx-proxy.
...

This line in entrypoint.sh is where the problem is coming from. After some debugging, I saw that the call of docker_api "/containers/$CONTAINER_ID/json" was returning nothing (the curl command it was executing was this: curl -s --unix-socket /var/run/docker.sock -XGET http:/containers/$CONTAINER_ID/json).

Any idea what's going on?

Most helpful comment

I had the same issue. For me the problem was that docker-compose sometimes startet the nginx container AFTER the letsencrypt companion. I solved with depends:

version: '3.5'

services:
  nginx-proxy:
    image: jwilder/nginx-proxy
    container_name: nginx-proxy
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - html:/usr/share/nginx/html
      - dhparam:/etc/nginx/dhparam
      - vhost:/etc/nginx/vhost.d
      - certs:/etc/nginx/certs:ro
      - /var/run/docker.sock:/tmp/docker.sock:ro
    labels:
      - "com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy"

  letsencrypt:
    image: jrcs/letsencrypt-nginx-proxy-companion
    container_name: nginx-proxy-lets-encrypt
    depends_on:
      - "nginx-proxy"
    volumes:
      - certs:/etc/nginx/certs:rw
      - vhost:/etc/nginx/vhost.d
      - html:/usr/share/nginx/html
      - /var/run/docker.sock:/var/run/docker.sock:ro

volumes:
  certs:
  html:
  vhost:
  dhparam:

All 5 comments

Like said in the log it seems that the nginx volumes are not mount into the letsencrypt container.
I never use docker-compose to start the containers. For working docker-compose examples look in the README (in the examples section)

In fact, it mounts. The issue is that this makes use of multi mounting in case you wan't to scale.

@nwallace Please do this change:

letsencrypt:
  image: jrcs/letsencrypt-nginx-proxy-companion
  restart: always
  volumes_from:
-    - nginx
+    - container:servicename_nginx_1
  volumes:
    - "/var/run/docker.sock:/var/run/docker.sock:ro"
    - "./volumes/etc/nginx/certs:/etc/nginx/certs:rw"

Inspite, IMO it should also be supported by exposing it over an ENV VAR.

had the same problem -> removed container and built again

I had the same issue. For me the problem was that docker-compose sometimes startet the nginx container AFTER the letsencrypt companion. I solved with depends:

version: '3.5'

services:
  nginx-proxy:
    image: jwilder/nginx-proxy
    container_name: nginx-proxy
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - html:/usr/share/nginx/html
      - dhparam:/etc/nginx/dhparam
      - vhost:/etc/nginx/vhost.d
      - certs:/etc/nginx/certs:ro
      - /var/run/docker.sock:/tmp/docker.sock:ro
    labels:
      - "com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy"

  letsencrypt:
    image: jrcs/letsencrypt-nginx-proxy-companion
    container_name: nginx-proxy-lets-encrypt
    depends_on:
      - "nginx-proxy"
    volumes:
      - certs:/etc/nginx/certs:rw
      - vhost:/etc/nginx/vhost.d
      - html:/usr/share/nginx/html
      - /var/run/docker.sock:/var/run/docker.sock:ro

volumes:
  certs:
  html:
  vhost:
  dhparam:
Was this page helpful?
0 / 5 - 0 ratings

Related issues

maitrungduc1410 picture maitrungduc1410  路  5Comments

synopsisdevs picture synopsisdevs  路  7Comments

codeHorse87 picture codeHorse87  路  4Comments

rene-gomez picture rene-gomez  路  5Comments

DatAres37 picture DatAres37  路  5Comments