From 3c877181d83e1c23fad2ec937d720bd3961dfba4 Mon Sep 17 00:00:00 2001 From: Emmet O'Grady Date: Sat, 4 Mar 2017 14:15:15 -0600 Subject: [PATCH 1/4] Get nginx container id from labelled container --- app/entrypoint.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/entrypoint.sh b/app/entrypoint.sh index 3b3232ab..bc3f72ef 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["jrcs.nginx_letsencrypt_companion.is_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 'jrcs.nginx_letsencrypt_companion.is_proxy=true'." >&2 exit 1 fi } From 07b04f2f9a63c0b28b9e7b55898eb7cf0f3742b8 Mon Sep 17 00:00:00 2001 From: Emmet O'Grady Date: Sat, 4 Mar 2017 14:29:33 -0600 Subject: [PATCH 2/4] Update the README with instructions on new label --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 77fc1de6..4d17db19 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 jrcs.nginx_letsencrypt_companion.is_proxy=true \ jwilder/nginx-proxy ``` +The "jrcs.nginx_letsencrypt_companion.is_proxy" 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 jrcs.nginx_letsencrypt_companion.is_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 "jrcs.nginx_letsencrypt_companion.is_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: From 8b71ed56e79d76dedf178e72fd112753e072ab5c Mon Sep 17 00:00:00 2001 From: Emmet O'Grady Date: Sat, 4 Mar 2017 14:30:26 -0600 Subject: [PATCH 3/4] Make label clearer --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4d17db19..b54b7693 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ $ docker run -d -p 80:80 -p 443:443 \ --label jrcs.nginx_letsencrypt_companion.is_proxy=true \ jwilder/nginx-proxy ``` -The "jrcs.nginx_letsencrypt_companion.is_proxy" label is needed so that the letsencrypt container knows which nginx proxy container to use. +The "jrcs.nginx_letsencrypt_companion.is_proxy=true" label is needed so that the letsencrypt container knows which nginx proxy container to use. * Second start this container: ```bash From a1af285d46d181c1eec4e939ba95d47d10a49d88 Mon Sep 17 00:00:00 2001 From: Emmet O'Grady Date: Thu, 13 Apr 2017 12:09:13 +0100 Subject: [PATCH 4/4] Use fully qualified label name --- README.md | 8 ++++---- app/entrypoint.sh | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index b54b7693..b7285a43 100644 --- a/README.md +++ b/README.md @@ -30,10 +30,10 @@ $ 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 jrcs.nginx_letsencrypt_companion.is_proxy=true \ + --label com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy=true \ jwilder/nginx-proxy ``` -The "jrcs.nginx_letsencrypt_companion.is_proxy=true" label is needed so that the letsencrypt container knows which nginx proxy container to use. +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 @@ -74,7 +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 jrcs.nginx_letsencrypt_companion.is_proxy=true \ + --label com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy=true \ nginx ``` @@ -150,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. -* The "jrcs.nginx_letsencrypt_companion.is_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. +* 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 bc3f72ef..a98d7aba 100755 --- a/app/entrypoint.sh +++ b/app/entrypoint.sh @@ -34,13 +34,13 @@ function get_nginx_proxy_cid { 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["jrcs.nginx_letsencrypt_companion.is_proxy"] == "true")|.Id') + 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 or label the nginx proxy container to use with 'jrcs.nginx_letsencrypt_companion.is_proxy=true'." >&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 }