[英]How to copy file from docker virtual machine to the host on OS X?
I use OS X 10.13.3
, and my docker version as follow:我使用
OS X 10.13.3
,我的OS X 10.13.3
版本如下:
Client:
Version: 17.12.0-ce
API version: 1.35
Go version: go1.9.2
Git commit: c97c6d6
Built: Wed Dec 27 20:03:51 2017
OS/Arch: darwin/amd64
Server:
Engine:
Version: 17.12.0-ce
API version: 1.35 (minimum version 1.12)
Go version: go1.9.2
Git commit: c97c6d6
Built: Wed Dec 27 20:12:29 2017
OS/Arch: linux/amd64
Experimental: true
I know docker is running in a vm on OS X, and I can get in by following command:我知道 docker 正在 OS X 上的虚拟机中运行,我可以通过以下命令进入:
screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty
In docker's history version, docker use Docker.qcow2
as the image of vm.在
Docker.qcow2
的历史版本中, Docker.qcow2
使用Docker.qcow2
作为vm的镜像。 Local /Users
direcotry is mounted into the docker vm, so I can copy a file to my home directory, such as /Users/username/Downloads
:本地
/Users
挂载到 docker vm 中,因此我可以将文件复制到我的主目录,例如/Users/username/Downloads
:
cp /var/lib/docker/image/overlay2/repositories.json /Users/username/Downloads
In latest version, Docker use Docker.raw
as the image of vm, and I can't copy file in that way.在最新版本中,Docker 使用
Docker.raw
作为 vm 的镜像,我无法通过这种方式复制文件。
How can I copy file from the vm to my OS X?如何将文件从虚拟机复制到我的 OS X?
A possible workaround:一个可能的解决方法:
Add a local directory as a volume(bind-mount) for a container.添加本地目录作为容器的卷(绑定安装)。 In
docker-compose.yml
this would be like:在
docker-compose.yml
这将是这样的:
volumes:
- wpdb:/var/lib/mysql
- ./db:/root
wpdb
is a docker volume would be inside the linux vm and inaccessible from the local mac directory wpdb
是一个wpdb
卷,它位于 linux vm 内,无法从本地 mac 目录访问
./db
would be a bind-mount and accessible in the same directory as your docker-compose.yml
file ./db
将是一个绑定安装并且可以在与docker-compose.yml
文件相同的目录中访问
Any file you copy into the /root
directory would be available in your local mac directory ./db
.您复制到
/root
目录中的任何文件都可以在本地 mac 目录./db
。
In the example above:在上面的例子中:
- ./db:/root
would be a bind-mount.将是一个绑定安装。
This article may explain it more clearly:这篇文章可能会解释得更清楚:
Choosing Between Volume & Bind Mount 在卷和绑定挂载之间进行选择
docker run -v $PWD:/home containername
It can be done by using docker cp可以通过使用 docker cp 来完成
docker cp <CONTAINER_ID>:<SRC_PATH_ON_CONTAINER> <DEST_PATH_ON_LOCAL_MACHINE>
More details: Docker docs更多细节: Docker 文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.