Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker-compose won't use my named volumes

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?

like image 570
navanjr Avatar asked Jun 22 '17 18:06

navanjr


People also ask

Does Docker compose down Remove named volumes?

Networks and volumes defined as external are never removed. Anonymous volumes are not removed by default.

Where are named docker volumes stored?

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.

Does Docker compose create volume?

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.


1 Answers

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

like image 96
programmerq Avatar answered Sep 20 '22 18:09

programmerq