Docker撰写命名卷:在主机上查找卷 [英] Docker compose named volume: find volume on host machine
问题描述
我有一个docker-compose.yml:
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:
当我运行此 docker-compose up -d
然后执行 docker inspect -f'{{(index .Mounts 0).Source}}'ef8be254a08b
正在运行的db容器以获取指定主机上卷位置的Source,如果我 ls
目录( ls/var/lib/docker/volumes/test_db_data/_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?
推荐答案
所以我得到了答案.要点是Mac上的Docker 仍在VM内运行.因此,系统路径仍然是相对于VM的,而不是相对于Mac的.所有容器都存储在VM中,并位于〜/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/Docker.qcow2
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
然后您可以看到 docker inspect {container_id}
中给出的Source文件夹的内容:
Then you can see contents of the Source folder given in docker inspect {container_id}
:
ls /var/lib/docker/volumes/test_db_data/_data
这篇关于Docker撰写命名卷:在主机上查找卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!