Docker 挂载不把文件放到hosts目录

Docker mount not putting files to the hosts directory

我在我的容器上创建了一个挂载,它将服务器上的物理路径映射到 docker 容器内的路径。但是,当文件放在容器路径中时,这些文件不会出现在服务器路径中(反之亦然)

这是我的 docker 运行 命令:

docker run -d -p 127.0.0.1:7001:5000 --name myContainer myContainer -v /var/www/Images:/app/wwwroot/

服务器是 运行ning CentOS。我的 运行 在此 docker 容器中的应用程序将文件放置在其容器内的 app/wwwroot 文件夹中。我希望这些文件也出现在服务器 /var/www/Images 文件夹中,但它们没有。

知道为什么吗?

谢谢

I expected these files to also appear on the servers /var/www/Images folder but they do not.

你映射挂载一个目录或路径 /app/wwwroot 将被主机文件覆盖(隐藏),因为 -v 选项告诉 docker 我将覆盖里面的任何东西Docker 包含主机文件。

When you use a bind mount, a file or directory on the host machine is mounted into a container. The file or directory is referenced by its full or relative path on the host machine.

bind-mounts

或者,如果您希望从容器中复制,那么一种方法是启动容器

docker run -it --rm --name test my_container

然后从容器中复制文件

docker cp my_container:/app/wwwroot/  /var/www/Images

现在绑定您在 /var/www/Images.

下有 docker 个文件