如何将文件从Windows主机复制到Docker容器

如何将文件从Windows主机复制到Docker容器

问题描述:

寻找一种快速的解决方案,将本地文件复制到Windows上的Docker容器。我无法在其他Stack Overflow解决方案中找到它。

Looking for a quick solution to copy local files to a Docker container on Windows. I wasn't able to find this in other Stack Overflow solutions.

您可能会称其为将Windows本地驱动器安装在Docker容器中。

You might call this mounting a local drive on Windows within a docker container.

从任务栏上的图标打开Docker设置:

Open the Docker settings from the icon on the taskbar:

转到共享驱动器并使您的容器可以访问本地驱动器:

Go to 'Shared Drives' and enable your local drive to be made accessible to your containers:

现在,您可以将共享驱动器中的文件夹作为卷添加到容器中。使用Docker中的 nginx 示例获取入门指南

Now you can add folders from your shared drive as a volume in a container. Using the nginx example from the Docker getting started guide:

docker run -it -vc:/用户:/ data nginx / bin / bash

这将为您提供外壳程序访问权限,您可以在其中在nginx容器的/ data目录中找到本地文件(c:/ Users)。

That will give you shell access, where you can find your local files (c:/Users) in the /data directory of your nginx container.