Skip to content

Commit

Permalink
Merge pull request #181 from emmetog/patch-1
Browse files Browse the repository at this point in the history
Get nginx container id from labelled container
  • Loading branch information
JrCs authored Apr 13, 2017
2 parents 4456027 + a1af285 commit 794d777
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down Expand Up @@ -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
```

Expand Down Expand Up @@ -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.

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

Expand Down
7 changes: 6 additions & 1 deletion app/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 794d777

Please sign in to comment.