I'm using named volumes with docker-compose v2. When I start the container, the certificates are getting saved in every mounted volume. The same certificates are saved inside certs, conf.d, vhost.d, html and test. Is this the normal behavior? How can I prevent that the certificates are getting saved inside vhost.d?
Docker-compose:
letsencrypt-nginx-proxy-companion:
build:
context: .
dockerfile: Dockerfile.letsencrypt-nginx-proxy-companion
container_name: letsencrypt-nginx-proxy-companion
depends_on:
- nginx-gen
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- nginxstore:/etc/nginx/certs:rw
- nginxstore:/etc/nginx/conf.d
- nginxstore:/etc/nginx/vhost.d
- nginxstore:/usr/share/nginx/html
- nginxstore:/etc/test
environment:
- NGINX_DOCKER_GEN_CONTAINER=nginx-gen
- ACME_CA_URI=https://acme-staging.api.letsencrypt.org/directory
- DEBUG=true
networks:
- back-tier
You are using the same volume for all the directories. Use different volumes for each dir or at least for the certs.
Why do I have to use different volumes?
This is my complete docker-compose file.
version: "2"
services:
nginx:
build:
context: .
dockerfile: Dockerfile.nginx
container_name: nginx
ports:
- "80:80"
- "443:443"
volumes:
- nginxstore:/etc/nginx/certs:ro
- nginxstore:/etc/nginx/conf.d
- nginxstore:/etc/nginx/vhost.d
- nginxstore:/usr/share/nginx/html
networks:
- front-tier
- back-tier
nginx-gen:
build:
context: .
dockerfile: Dockerfile.docker-gen
container_name: nginx-gen
depends_on:
- nginx
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- nginxstore:/etc/nginx/certs:ro
- nginxstore:/etc/nginx/conf.d
- nginxstore:/etc/nginx/vhost.d
- nginxstore:/usr/share/nginx/html
entrypoint: /usr/local/bin/docker-gen -notify-sighup nginx -watch -wait 5s:30s /etc/docker-gen/templates/nginx.tmpl /etc/nginx/conf.d/default.conf
networks:
- back-tier
letsencrypt-nginx-proxy-companion:
build:
context: .
dockerfile: Dockerfile.letsencrypt-nginx-proxy-companion
container_name: letsencrypt-nginx-proxy-companion
depends_on:
- nginx-gen
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- nginxstore:/etc/nginx/certs:rw
- nginxstore:/etc/nginx/conf.d
- nginxstore:/etc/nginx/vhost.d
- nginxstore:/usr/share/nginx/html
environment:
- NGINX_DOCKER_GEN_CONTAINER=nginx-gen
#- ACME_CA_URI=https://acme-staging.api.letsencrypt.org/directory
#- DEBUG=true
networks:
- back-tier
volumes:
#######################################
# Storage nginxstore
#######################################
nginxstore:
driver: local
networks:
front-tier:
driver: bridge
back-tier:
You can correct me, if I am wrong. But you can imagine the volume being a folder from the Docker host machine that is mounted inside the container. So you mount the same folder to multiple folders inside the container.
- nginxstore:/etc/nginx/certs:rw
- nginxstore:/etc/nginx/conf.d
- nginxstore:/etc/nginx/vhost.d
- nginxstore:/usr/share/nginx/html
- nginxstore:/etc/test
They all point to the same physical folder, but you expect to see the certificates in some of those mount points, but not on others. How should this work?
Most helpful comment
You can correct me, if I am wrong. But you can imagine the volume being a folder from the Docker host machine that is mounted inside the container. So you mount the same folder to multiple folders inside the container.
They all point to the same physical folder, but you expect to see the certificates in some of those mount points, but not on others. How should this work?