2019-01-11 18:58:49 +01:00
## Usage with Docker Compose
2021-04-04 22:58:22 +02:00
As stated by its repository, [Docker Compose ](https://github.com/docker/compose ) is a tool for defining and running multi-container Docker applications using a single _Compose file_ . This Wiki page is not meant to be a definitive reference on how to run **nginx-proxy** and **acme-companion** with Docker Compose, as the number of possible setups is quite extensive and they can't be all covered.
2019-01-11 18:58:49 +01:00
### Before your start
2021-05-06 19:01:19 +02:00
Be sure to be familiar with both the [basic ](./Basic-usage.md ) and [advanced ](./Advanced-usage.md ) non compose setups, and Docker Compose usage.
2019-01-11 18:58:49 +01:00
Please read [getting container IDs ](./Getting-containers-IDs.md ) and be aware that the `--volumes-from method` is **only** available on compose file version 2.
The following examples are minimal, clean starting points using compose file version 2. Again they are not intended as a definitive reference.
The use of named containers and volume is not required but helps keeping everything clear and organized.
### Two containers example
```yaml
version: '2'
services:
nginx-proxy:
2021-04-02 16:32:59 +02:00
image: nginxproxy/nginx-proxy
2019-01-11 18:58:49 +01:00
container_name: nginx-proxy
ports:
- "80:80"
- "443:443"
volumes:
- conf:/etc/nginx/conf.d
- vhost:/etc/nginx/vhost.d
- html:/usr/share/nginx/html
- certs:/etc/nginx/certs:ro
- /var/run/docker.sock:/tmp/docker.sock:ro
network_mode: bridge
2021-04-04 22:58:22 +02:00
acme-companion:
image: nginxproxy/acme-companion
container_name: nginx-proxy-acme
2022-04-11 23:29:30 +02:00
environment:
- DEFAULT_EMAIL=mail@yourdomain.tld
2019-01-11 18:58:49 +01:00
volumes_from:
- nginx-proxy
volumes:
- certs:/etc/nginx/certs:rw
2020-10-13 21:04:05 +02:00
- acme:/etc/acme.sh
2019-01-11 18:58:49 +01:00
- /var/run/docker.sock:/var/run/docker.sock:ro
network_mode: bridge
volumes:
conf:
vhost:
html:
certs:
2020-10-13 21:04:05 +02:00
acme:
2019-01-11 18:58:49 +01:00
```
### Three containers example
```yaml
version: '2'
services:
nginx-proxy:
image: nginx:alpine
container_name: nginx-proxy
ports:
- "80:80"
- "443:443"
volumes:
- conf:/etc/nginx/conf.d
- vhost:/etc/nginx/vhost.d
- html:/usr/share/nginx/html
- certs:/etc/nginx/certs:ro
network_mode: bridge
docker-gen:
2021-06-16 17:12:30 +02:00
image: nginxproxy/docker-gen
2019-01-11 18:58:49 +01:00
container_name: nginx-proxy-gen
2024-05-01 13:44:05 +02:00
command: -notify-sighup nginx-proxy -watch -wait 5s:30s /etc/docker-gen/templates/nginx.tmpl /etc/nginx/conf.d/default.conf
2019-01-11 18:58:49 +01:00
volumes_from:
- nginx-proxy
volumes:
- /path/to/nginx.tmpl:/etc/docker-gen/templates/nginx.tmpl:ro
- /var/run/docker.sock:/tmp/docker.sock:ro
labels:
2023-08-01 21:45:39 +02:00
- "com.github.nginx-proxy.docker-gen"
2019-01-11 18:58:49 +01:00
network_mode: bridge
2021-04-04 22:58:22 +02:00
acme-companion:
image: nginxproxy/acme-companion
container_name: nginx-proxy-acme
2022-04-11 23:29:30 +02:00
environment:
- DEFAULT_EMAIL=mail@yourdomain.tld
2019-01-11 18:58:49 +01:00
volumes_from:
- nginx-proxy
volumes:
- certs:/etc/nginx/certs:rw
2020-10-13 21:04:05 +02:00
- acme:/etc/acme.sh
2019-01-11 18:58:49 +01:00
- /var/run/docker.sock:/var/run/docker.sock:ro
network_mode: bridge
volumes:
conf:
vhost:
html:
certs:
2020-10-13 21:04:05 +02:00
acme:
2019-01-11 18:58:49 +01:00
```
2021-04-05 14:31:53 +02:00
**Note:** don't forget to replace `/path/to/nginx.tmpl` with the actual path to the [`nginx.tmpl` ](https://raw.githubusercontent.com/nginx-proxy/nginx-proxy/main/nginx.tmpl ) file you downloaded.
2019-01-11 18:58:49 +01:00
### Other (external) examples
2021-03-16 22:58:45 +01:00
**Warning:** some of those examples might be outdated and not working properly with version >= `2.0` of this project.
2019-01-11 18:58:49 +01:00
If you want other examples how to use this container with Docker Compose, look at:
* [Nicolas Duchon's Examples ](https://github.com/buchdag/letsencrypt-nginx-proxy-companion-compose ) - with automated testing
* [Evert Ramos's Examples ](https://github.com/evertramos/docker-compose-letsencrypt-nginx-proxy-companion ) - using docker-compose version '3'
* [Karl Fathi's Examples ](https://github.com/fatk/docker-letsencrypt-nginx-proxy-companion-examples )
* [More examples from Karl ](https://github.com/pixelfordinner/pixelcloud-docker-apps/tree/master/nginx-proxy )
* [George Ilyes' Examples ](https://github.com/gilyes/docker-nginx-letsencrypt-sample )
* [Dmitry's simple docker-compose example ](https://github.com/dmitrym0/simple-lets-encrypt-docker-compose-sample )
* [Radek's docker-compose jenkins example ](https://github.com/dataminelab/docker-jenkins-nginx-letsencrypt )