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?
Networks and volumes defined as external are never removed. Anonymous volumes are not removed by default.
Volumes are stored in a part of the host filesystem which is managed by Docker ( /var/lib/docker/volumes/ on Linux). Non-Docker processes should not modify this part of the filesystem. Volumes are the best way to persist data in Docker.
Here's an example of a single Docker Compose service with a volume: services: frontend: image: node:lts volumes: - myapp:/home/node/app volumes: myapp: Running docker compose up for the first time creates a volume. The same volume is reused when you subsequently run the command.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With