[英]Docker mount files to my local system while running the container
I am using an image academind/node-example-1 which is a simple node image.我正在使用图像 academind/node-example-1,它是一个简单的节点图像。 You can check it https://hub.docker.com/r/academind/node-example-1 here.
您可以在此处查看https://hub.docker.com/r/academind/node-example-1 。 What I want while I run the image I want to get the same folder & file structure that is there in the Image.
在运行图像时我想要什么我想获得与图像中相同的文件夹和文件结构。 I know that can be done via volume.
我知道这可以通过音量来完成。 When I use like
当我使用喜欢
docker run -d --rm --name node-test -p 5000:80 academind/node-example-1
Everything is proper But I want to get the codebase while running, so I tried like一切正常但我想在运行时获取代码库,所以我尝试了
docker run -d --rm --name node-test -p 5000:80 -v /Users/souravbanerjee/Documents/node-docker:node-example-1 academind/node-example-1
Here node-docker is my local folder where I expect the code to be.这里node-docker是我希望代码所在的本地文件夹。 It runs but not getting the files in the local machine, I'm in doubt here where the source_path:destination_path.
它运行但没有在本地机器中获取文件,我在这里怀疑 source_path:destination_path 在哪里。 Please correct me to please tell me where I'm wrong, or what to do, or my entire thinking is going in the wrong direction or not.
请纠正我,请告诉我我错在哪里,或者该怎么做,或者我的整个想法是否朝着错误的方向发展。
Thanks.谢谢。
If you read the official doc , you'll see that the first part of the :
should be the path somewhere in the host machine (which you're doing), while the later part should match the path "inside" the container (instead you're using image name).如果你读了官方的文档,你会看到的第一部分
:
应该是在主机(你在做这)路径的某处,而后面的部分应与路径“内部”容器(而不是您正在使用图像名称)。 Assuming /app
being the path (I've taken that course by myself and this is the path AFAIR), it should be:假设
/app
是路径(我自己完成了这门课程,这是 AFAIR 的路径),它应该是:
docker run -d --rm --name node-test -p 5000:80 -v /Users/souravbanerjee/Documents/node-docker:/app academind/node-example-1
I think the correct syntax is to enter the drive information in the volume mapping.我认为正确的语法是在卷映射中输入驱动器信息。
Eg.例如。 Users/xxxx/:some/drive/location
用户/xxxx/:some/drive/location
However, that would map your empty drive at xxxx over the top of 'location' folder.但是,这会将 xxxx 处的空驱动器映射到“位置”文件夹的顶部。 Thus deleting the existing files in the container.
从而删除容器中的现有文件。
If you are interested in seeing the contents of the files in the container, you should consider using 'Docker CP' command.如果您有兴趣查看容器中文件的内容,您应该考虑使用“Docker CP”命令。
People often use volume mounts to push data (ie persistent database files) into a container.人们经常使用卷挂载将数据(即持久数据库文件)推送到容器中。
Alternatively, writing log files to the volume mounted location inside the application container.或者,将日志文件写入应用程序容器内的卷安装位置。 Then those files are then reflected on your local drive
然后这些文件会反映在您的本地驱动器上
You can copy the files to the current host directory using the command您可以使用以下命令将文件复制到当前主机目录
docker cp node-test:/app .
when the container is running当容器运行时
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.