0

After running docker-compose file 1, I want to use one of its named volumes in docker-compose file 2. I tried the below.

What should I be doing instead please? Thanks.

docker-compose file 1 (excerpt) in 'nginx-proxy' folder:

services:
  nginx:
    volumes:
      - certs:/etc/nginx/certs

volumes:
  certs:            // this produces a container called `nginx-proxy_certs`

networks:
  default:
    external:
      name: nginx-proxy

docker-compose file 2 (excerpt) in 'mailserver' folder:

services:
  mailserver:
    volumes:
      - certs:/etc/letsencrypt

volumes:
  certs:              // this produces a container called `mailserver_certs`

networks:
  default:
    external:
      name: nginx-proxy
thanks_in_advance
  • 2,603
  • 6
  • 28
  • 44
  • 1
    I would say if possible put both services in the same compose file, but if you need to keep them separate look at using external volumes https://github.com/compose-spec/compose-spec/blob/master/spec.md#external-1 and you can see a potential example here https://codebeamer.com/cb/wiki/5713519 – camba1 Feb 13 '21 at 06:49
  • @camba1 Thank you very much, and upvoted. Question. in the 2nd link, this bit: `volumes: codebeamer-db-data: name: codebeamer-db-data external: true` ... why is the `name` replicated? Can it also be written as `volumes: codebeamer-db-data: external: true`... thanks! – thanks_in_advance Feb 13 '21 at 18:03
  • 1
    The first one is the name is the alias used to refer to the volume within the docker-compose file and the second is the reference to the actual external volume. – camba1 Feb 13 '21 at 21:47

0 Answers0