Skip to content

Commit 794d777

Browse files
authored
Merge pull request #181 from emmetog/patch-1
Get nginx container id from labelled container
2 parents 4456027 + a1af285 commit 794d777

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@ $ docker run -d -p 80:80 -p 443:443 \
3030
-v /etc/nginx/vhost.d \
3131
-v /usr/share/nginx/html \
3232
-v /var/run/docker.sock:/tmp/docker.sock:ro \
33+
--label com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy=true \
3334
jwilder/nginx-proxy
3435
```
36+
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.
3537

3638
* Second start this container:
3739
```bash
3840
$ docker run -d \
3941
-v /path/to/certs:/etc/nginx/certs:rw \
40-
--volumes-from nginx-proxy \
4142
-v /var/run/docker.sock:/var/run/docker.sock:ro \
4243
jrcs/letsencrypt-nginx-proxy-companion
4344
```
@@ -73,6 +74,7 @@ $ docker run -d -p 80:80 -p 443:443 \
7374
-v /etc/nginx/vhost.d \
7475
-v /usr/share/nginx/html \
7576
-v /path/to/certs:/etc/nginx/certs:ro \
77+
--label com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy=true \
7678
nginx
7779
```
7880

@@ -148,7 +150,7 @@ $ docker run -d \
148150

149151
* `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.
150152

151-
* `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.
153+
* 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.
152154

153155
* `ACME_TOS_HASH` - Let´s you pass an alternative TOS hash to simp_le, to support other CA´s ACME implentation.
154156

app/entrypoint.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,14 @@ function get_nginx_proxy_cid {
3333
break
3434
fi
3535
done
36+
# Check if any container has been labelled as the nginx proxy container.
37+
local labeled_cid=$(docker_api "/containers/json" | jq -r '.[] | select( .Labels["com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy"] == "true")|.Id')
38+
if [[ ! -z "${labeled_cid:-}" ]]; then
39+
export NGINX_PROXY_CONTAINER=$labeled_cid
40+
fi
3641
if [[ -z "${NGINX_PROXY_CONTAINER:-}" ]]; then
3742
echo "Error: can't get nginx-proxy container id !" >&2
38-
echo "Check that you use the --volumes-from option to mount volumes from the nginx-proxy." >&2
43+
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
3944
exit 1
4045
fi
4146
}

0 commit comments

Comments
 (0)