Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker volume data gets stored twice?

I am using a mysql docker image through docker-compose and I get its data stored twice (on the host and in docker data folder). What I want is to have one copy of mysql data stored on the "host". I've read through the docker and docker-compose docs and I don't seem to get how this is supposed to be working.

Here is the docker-compose config I am using:

version: '3.7'

services:
  mysql:
    image: mysql:5.7
    container_name: "mysql"
    ports:
      - "127.0.0.1:3306:3306"
    volumes:
      - mysql-data:/var/lib/mysql
volumes:
  mysql-data:
    driver: local
    driver_opts:
      device: /local/path
      o: bind

When I inspect the disk contents I can see that the mysql data is stored twice:

  • inside the docker data folder, e.g. /var/lib/docker/volumes/myapp_mysql-data/_data
  • on the "host" at /local/path

Is this "normal"? What do people use to have mysql in docker but its data located somewhere else?

Updated: Here is the output of the docker volume inspect myapp_mysql-data:

docker volume inspect myapp_mysql-data
[
    {
        "CreatedAt": "...",
        "Driver": "local",
        "Labels": {
            "com.docker.compose.project": "myapp",
            "com.docker.compose.version": "1.24.0",
            "com.docker.compose.volume": "mysql-data"
        },
        "Mountpoint": "/var/lib/docker/volumes/myapp_mysql-data/_data",
        "Name": "myapp_mysql-data",
        "Options": {
            "device": "/local/path",
            "o": "bind"
        },
        "Scope": "local"
    }
]

like image 369
Alexandr Sugak Avatar asked Jun 29 '26 07:06

Alexandr Sugak


1 Answers

OK, looks like it works as expected, i.e. docker has volume's _data folder binded to the same location as local path. Thanks @danblack!

The reason for my confusion was ncdu tool that I used to see what takes space on disks, which (after I moved the docker data folder to another disk) showed both folders as if they take the same amount of space.

like image 143
Alexandr Sugak Avatar answered Jul 01 '26 21:07

Alexandr Sugak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!