Docker 组合命名卷:在主机上查找卷 [英] Docker compose named volume: find volume on host machine

查看:24
本文介绍了Docker 组合命名卷:在主机上查找卷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 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 for正在运行的 db 容器获取指定主机上卷位置的源,如果我 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

进入虚拟机使用:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆