更新时间:2023-11-18 17:22:46
使用 -v 标志运行容器时,这意味着将Docker引擎主机中的目录装载到容器中,将覆盖您在 / home / Documents /节点应用,例如npm install。
When you run your container with -v flag, which mean mount a directory from your Docker engine’s host into a container, will overwrite what you do in /home/Documents/node-app,such as npm install.
因此您看不到 n容器中的ode_modules目录。
$ docker run -d -P --name web -v / src / webapp: / webapp training / webapp python app.py
$ docker run -d -P --name web -v /src/webapp:/webapp training/webapp python app.py
此命令将主机目录/ src / webapp挂载到/ webapp的容器中。如果路径/ webapp已存在于容器的映像中,则/ src / webapp安装会覆盖,但不会删除先前存在的内容。除去安装后,即可再次访问内容。这与mount命令的预期行为一致。
This command mounts the host directory, /src/webapp, into the container at /webapp. If the path /webapp already exists inside the container’s image, the /src/webapp mount overlays but does not remove the pre-existing content. Once the mount is removed, the content is accessible again. This is consistent with the expected behavior of the mount command.
将主机目录安装为数据卷。正如文档所说, -主机目录中的现有内容将不会被删除,但是不会包含有关容器的现有目录上正在发生的事情的信息。
mount a host directory as a data volume.As what the docs said,the pre-existing content of host directory will not be removed, but no information about what's going on the exist directory of the container.
有一个例子可以支持我的观点。
There is a example to support my opinion.
Dockerfile
Dockerfile
FROM alpine:latest
WORKDIR / usr / src / app
COPY。 。
我在Dockerfile的同一目录中创建了一个 test.t 文件。
I create a test.t file in the same directory of Dockerfile.
证明
docker build -t test-1。
docker run --name test-c-1 -it test-1 / bin / sh
,那么您的容器将打开bash。 ls -l ,它将显示test.t文件。
docker run --name test-c -2 -v / home:/ usr / src / app -it test-1 / bin / sh
。您无法在 test-c-2 容器中找到文件 test.t 。docker build -t test-1 .
docker run --name test-c-1 -it test-1 /bin/sh
,then your container will open bash.ls -l
in your container bash,it will show test.t file.docker run --name test-c-2 -v /home:/usr/src/app -it test-1 /bin/sh
. You cannot find the file test.t in your test-c-2 container.
仅此而已,希望对您有所帮助。
That's all.I hope it will help you.