[英]How to share data between the docker container and the host?
I tried to share data between the docker container and the host, for example by adding the parameter -v /Users/name/Desktop/Tutorials:/cntk/Tutorials to the docker run command, but I noticed that it also deletes all the files on the docker contained in /cntk/Tutorials.我尝试在 docker 容器和主机之间共享数据,例如通过将参数 -v /Users/name/Desktop/Tutorials:/cntk/Tutorials 添加到 docker run 命令,但我注意到它还会删除所有文件在 /cntk/Tutorials 中包含的 docker 上。
My question is how to make the same link, but having instead all the files in /cntk/Tutorials copied to the host (at /Users/name/Desktop/Tutorials)我的问题是如何创建相同的链接,而是将 /cntk/Tutorials 中的所有文件复制到主机(位于 /Users/name/Desktop/Tutorials)
Thank you谢谢
Unfortunately that it is not possible, take a look here .不幸的是,这是不可能的, 请看这里。 That is because this is how mounting works in Linux.
那是因为这就是 Linux 中挂载的工作方式。
It is not correct to say that the files were deleted.说文件被删除是不正确的。 They are still present in the underlying image, but the act of mounting another directory at the same path has obscured them.
它们仍然存在于底层映像中,但是在同一路径上安装另一个目录的行为已经掩盖了它们。 They exist, but are not accessible in this condition.
它们存在,但在这种情况下无法访问。
One way you can accomplish this is by mounting a volume into your container at a different path , and then copying the container's files to that path.实现此目的的一种方法是将卷安装到容器中的不同路径,然后将容器的文件复制到该路径。 Something like this.
像这样的东西。
Mount a host volume using a different path than the one the container already has for the files you are interested in.使用与容器已有的用于您感兴趣的文件的路径不同的路径挂载主机卷。
docker run -v /Users/name/Desktop/Tutorials:/cntk/Tutorials2 [...]
Now, execute a command that will copy the files already in the docker image, into the mounted volume from the outside host.现在,执行一个命令,将 docker 镜像中已有的文件从外部主机复制到挂载的卷中。
docker exec <container-id> cp -r /cntk/Tutorials /cntk/Tutorials2
The docker cp
command allows you to copy files/folders on demand between host and the container: docker cp
命令允许您在主机和容器之间按需复制文件/文件夹:
docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-
docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH
docker cp ContainerName:/home/data.txt . <== copy from container to host
docker cp ./test.txt ContainerName:/test.txt <== copy from host to container
docker cp ContainerName:/test.txt ./test2.txt <== copy from container to host
For details run docker cp --help
有关详细信息,请运行
docker cp --help
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.