So I'm fairly new to docker. I have an issue with attaching my named volumes to services in my swarm.
Here is my docker-compose.yml...
version: '3'
services:
ned:
image: keli
ports:
- "8080:8080"
depends_on:
- craig
- paul
craig:
image: cb
volumes:
- cbKeli:/opt/couchbase/var
ports:
- "8091:8091"
paul:
image: pg
volumes:
- pgKeli:/var/lib/postgresql/data
ports:
- "5432:5432"
volumes:
pgKeli:
cbKeli:
However, after a docker-compose up
I end up with new volumes.
$ docker volume ls | grep -i keli
DRIVER VOLUME NAME
local cbKeli
local kelidocker_cbKeli
local kelidocker_pgKeli
local pgKeli
What's up with that? How can I get my new swarm to use an existing named volume?
You need to tell compose that this is an externally created volume. To do that, you use the external key on the volume definition like this:
volumes:
cbKeli:
external: true
pgKeli:
external: true
See the following documentation for further information on external volumes: https://docs.docker.com/compose/compose-file/#external-1 (external is used for networks and config as well)