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:
/var/lib/docker/volumes/myapp_mysql-data/_data/local/pathIs 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"
}
]
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.
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