Docker compose named volume: find volume on host machine
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?
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
链接地址: http://www.djcxy.com/p/94262.html
上一篇: 动态使用服务加载NgModule entryComponents
下一篇: Docker组成命名卷:在主机上查找卷