Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker-compose and volumes

When I create a volume manually and include it in docker-compose, if I don't prefix the volume tag with docker_, docker compose creates a new volume prefixed with docker_ For example: I create a volume with:

docker volume create myvolume

It's visible at /var/lib/docker/volumes/myvolume. I include it in my docker-compose yaml file, but when I run docker-compose, a new volume is created at /var/lib/docker/volumes/docker_myvolume If I call my volume docker_myvolume and include that in my docker-compose yaml, it uses it and doesn't create it's own.

Is this normal behavior?

like image 848
wedwo Avatar asked Jun 12 '26 00:06

wedwo


1 Answers

Yes, this is normal behavior. When you specify a volume in your docker-compose.yml file without a leading driver_ prefix, Docker Compose will create a new volume with a name that is prefixed with driver_. This is because Docker Compose uses a default driver for creating and managing volumes, which is the local driver.

You can specify a volume in your docker-compose.yml file with the external option to tell Docker Compose to use an existing volume instead of creating a new one. For example:

version: '3'
services:
  myservice:
    volumes:
      - type: volume
        source: myvolume
        target: /app/data
        volume:
          external: true

This will tell Docker Compose to use the existing volume myvolume instead of creating a new one.

like image 67
Mustapha Hadid Avatar answered Jun 15 '26 02:06

Mustapha Hadid