Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for separate nginx and docker-gen containers #20

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,24 @@ Then start any containers you want to proxied with a env var `VIRTUAL_HOST=subdo

The containers being proxied must [expose](https://docs.docker.com/reference/run/#expose-incoming-ports) the port to be proxied, either by using the `EXPOSE` directive in their `Dockerfile` or by using the `--expose` flag to `docker run` or `docker create`. See [nginx-proxy](https://github.com/jwilder/nginx-proxy) for more informations. To generate automatically Let's Encrypt certificates see next section.

#### Separate Containers
nginx-proxy can also be run as two separate containers using the [jwilder/docker-gen](https://github.com/jwilder/docker-gen)
image and the official [nginx](https://hub.docker.com/_/nginx/) image.

* First start nginx and docker-gen containers separately following the instructions in [separate-container-install](https://github.com/jwilder/docker-gen#separate-container-install)

* 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 \
-v /tmp/templates:/etc/docker-gen/templates \
-e SEPARATE_CONTAINER_INSTALL=true \
jrcs/letsencrypt-nginx-proxy-companion
```
Then start any containers to be proxied as described previously.

#### Let's Encrypt

To use the Let's Encrypt service to automatically create a valid certificate for virtual host(s).
Expand Down
19 changes: 15 additions & 4 deletions app/functions.lib
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,20 @@ function docker_exec {

## Nginx
reload_nginx() {
if [[ -n "${NGINX_PROXY_CID:-}" ]]; then
echo "Reloading nginx proxy..."
docker_exec "$NGINX_PROXY_CID" \
'[ "sh", "-c", "/usr/local/bin/docker-gen -only-exposed /app/nginx.tmpl /etc/nginx/conf.d/default.conf; /usr/sbin/nginx -s reload" ]'

if [[ "${SEPARATE_CONTAINER_INSTALL}" == "true" ]]; then
echo "Generating nginx configuration..."
/usr/local/bin/docker-gen -only-exposed /etc/docker-gen/templates/nginx.tmpl /etc/nginx/conf.d/default.conf
if [[ -n "${NGINX_PROXY_CID:-}" ]]; then
echo "Reloading nginx proxy..."
docker_exec "$NGINX_PROXY_CID" \
'[ "sh", "-c", "/usr/sbin/nginx -s reload" ]'
fi
else
if [[ -n "${NGINX_PROXY_CID:-}" ]]; then
echo "Reloading nginx proxy..."
docker_exec "$NGINX_PROXY_CID" \
'[ "sh", "-c", "/usr/local/bin/docker-gen -only-exposed /app/nginx.tmpl /etc/nginx/conf.d/default.conf ; /usr/sbin/nginx -s reload" ]'
fi
fi
}