简体   繁体   English

Docker 在运行容器时将文件挂载到我的本地系统

[英]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.

相关问题 如何将本地源文件挂载到Docker容器? - How to mount my local source file to docker container? 黑猩猩在docker容器中运行时超时 - Chimp timing out while running in docker container 在 docker 容器中运行 JEST 时找不到 Jest - Jest not found while running JEST in docker container 在服务器上的Docker容器中运行Node-Red-在哪里存储数据文件(csv)? - Running Node-Red in a Docker Container on my Server - where store data files (csv)? 将nodejs(本地)连接到docker容器上运行的cassandra数据库 - Connect nodejs (local) to cassandra database running on docker container 如何在 kubernetes 中将具有数据(我需要此数据)的 pod 容器路径挂载到我的本地主机路径 - How to mount pod container path which is having data (I need this data)to my local host path in kubernetes 如何将主机代码挂载到Docker中的容器? - How to mount host codes to container in docker? Axios - 在 docker 容器上运行时出现套接字挂起错误 - Axios - Getting socket hang up error while running it on docker container "如何在运行 docker 容器时更新配置文件(.env 文件)" - How to update configuration file (.env file) while running docker container 运行 docker 容器时未找到 npm 命令错误 - npm command not found error while running docker container
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM