diff --git a/README.md b/README.md index 77fc1de6..b7285a43 100644 --- a/README.md +++ b/README.md @@ -30,14 +30,15 @@ $ docker run -d -p 80:80 -p 443:443 \ -v /etc/nginx/vhost.d \ -v /usr/share/nginx/html \ -v /var/run/docker.sock:/tmp/docker.sock:ro \ + --label com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy=true \ jwilder/nginx-proxy ``` +The "com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy=true" label is needed so that the letsencrypt container knows which nginx proxy container to use. * Second start this container: ```bash $ docker run -d \ -v /path/to/certs:/etc/nginx/certs:rw \ - --volumes-from nginx-proxy \ -v /var/run/docker.sock:/var/run/docker.sock:ro \ jrcs/letsencrypt-nginx-proxy-companion ``` @@ -73,6 +74,7 @@ $ docker run -d -p 80:80 -p 443:443 \ -v /etc/nginx/vhost.d \ -v /usr/share/nginx/html \ -v /path/to/certs:/etc/nginx/certs:ro \ + --label com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy=true \ nginx ``` @@ -148,7 +150,7 @@ $ docker run -d \ * `DEBUG` - Set it to `true` to enable debugging of the entrypoint script and generation of LetsEncrypt certificates, which could help you pin point any configuration issues. -* `NGINX_PROXY_CONTAINER`- If for some reason you can't use the docker --volumes-from option, you can specify the name or id of the nginx-proxy container with this variable. +* The "com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy=true" label - set this label on the nginx-proxy container to tell the docker-letsencrypt-nginx-proxy-companion container to use it as the proxy. #### Examples: diff --git a/app/entrypoint.sh b/app/entrypoint.sh index 3b3232ab..a98d7aba 100755 --- a/app/entrypoint.sh +++ b/app/entrypoint.sh @@ -33,9 +33,14 @@ function get_nginx_proxy_cid { break fi done + # Check if any container has been labelled as the nginx proxy container. + local labeled_cid=$(docker_api "/containers/json" | jq -r '.[] | select( .Labels["com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy"] == "true")|.Id') + if [[ ! -z "${labeled_cid:-}" ]]; then + export NGINX_PROXY_CONTAINER=$labeled_cid + fi if [[ -z "${NGINX_PROXY_CONTAINER:-}" ]]; then echo "Error: can't get nginx-proxy container id !" >&2 - echo "Check that you use the --volumes-from option to mount volumes from the nginx-proxy." >&2 + echo "Check that you use the --volumes-from option to mount volumes from the nginx-proxy or label the nginx proxy container to use with 'com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy=true'." >&2 exit 1 fi }