I have a docker-compose.yml:
version: '2'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: wordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_PASSWORD: wordpress
volumes:
db_data:
When I run this docker-compose up -d
and then do docker inspect -f '{{ (index .Mounts 0).Source }}' ef8be254a08b
for the running db container to get the Source which is specifying the volume location on the host, I always get "No such file or directory" if I ls
the directory (ls /var/lib/docker/volumes/test_db_data/_data: No such file or directory
).
How is that possible to get the real location for the volume?
Volumes are stored in a part of the host filesystem which is managed by Docker ( /var/lib/docker/volumes/ on Linux).
Volumes are also stored as part of the host file system, which is managed by Docker. On Linux, volumes are stored in “/var/lib/docker/volume”.
These volumes are created inside /var/lib/docker/volume local host directory. As we can see, we don't have to specify the host directory. We just need to specify the directory inside the container. If we remove the volume instruction from the docker-compose.
Find out the name of the volume with docker volume list. Shut down all running containers to which this volume is attached to. Run docker run -it --rm --mount source=[NAME OF VOLUME],target=/volume busybox. A shell will open.
So I got the answer. The main point is that Docker on Mac is still running inside a VM. So the system paths are still relative to the VM, and not to your Mac. All the containers are stored within VM and located at ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/Docker.qcow2
To go inside the VM use:
screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty
Then you can see contents of the Source folder given in docker inspect {container_id}
:
ls /var/lib/docker/volumes/test_db_data/_data
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