简体   繁体   English

Windows 上的 docker 工具箱挂载文件

[英]docker toolbox mount file on windows

I am a beginner with docker and I am using a windows machine.我是 docker 的初学者,我正在使用 Windows 机器。 But I have a problem mounting files using volumes.但是我在使用卷挂载文件时遇到问题。 The documentation says the following thing about mount files on OSX and windows :该文档说明了有关在 OSX 和 Windows 上挂载文件的以下内容:

Official docker docs :官方码头文档:

Note: If you are using Docker Machine on Mac or Windows, your Docker daemon only has limited access to your OS X/Windows filesystem.注意:如果您在 Mac 或 Windows 上使用 Docker Machine,您的 Docker 守护程序只能有限地访问您的 OS X/Windows 文件系统。 Docker Machine tries to auto-share your /Users (OS X) or C:\\Users (Windows) directory - and so you can mount files or directories using docker run -v /Users/:/ ... (OS X) or docker run -v /c/Users/:/ Docker Machine 尝试自动共享您的 /Users (OS X) 或 C:\\Users (Windows) 目录 - 因此您可以使用 docker run -v /Users/:/ ... (OS X) 或docker run -v /c/Users/:/

>> go to docker volumes docks >> 前往 docker 卷码头

I have a small nginx Dockerfile我有一个小的 nginx Dockerfile

Dockerfile文件

FROM centos:6.6

MAINTAINER afym

ENV WEBPORT 80

RUN yum -y update; yum clean all

RUN yum -y install epel-release; yum clean all

RUN yum -y install nginx; yum clean all

RUN echo "daemon off;" >> /etc/nginx/nginx.conf

VOLUME /usr/share/nginx/html

EXPOSE $WEBPORT

CMD [ "/usr/sbin/nginx" ]

Creating a simple container创建一个简单的容器

docker run -d --name simple -p 8082:80 ng1

8875448c01a4787f1ffe4c4c5c492efb039e452eff957391ac52a08915e18d66 8875448c01a4787f1ffe4c4c5c492efb039e452eff957391ac52a08915e18d66

在此处输入图片说明

Creating a container with a volume创建带有卷的容器

My windows host directory我的windows主机目录

在此处输入图片说明

Creating the docker container with -v option使用 -v 选项创建 docker 容器

docker run -d --name simple2 -v /c/Users/src:/usr/share/nginx/html -p 8082:80 ng1
invalid value "C:\\Users\\src;C:\\Program Files\\Git\\usr\\share\\nginx\\html" 
for flag -v: bad mount mode specified 
: \Program Files\Git\usr\share\nginx\html
See 'C:\Program Files\Docker Toolbox\docker.exe run --help'.

Inspecting the ng1 image检查 ng1 图像

docker inspect ng1

在此处输入图片说明

What is wrong when I am creating a docker container with a volume?创建带有卷的 docker 容器时有什么问题?

Thanks.谢谢。

Try to run it with additional / for volume like: 尝试使用额外/用于运行它,如:

docker run -d --name simple2 -v /c/Users/src://usr/share/nginx/html -p 8082:80 ng1

Or even for host OS, as 甚至对于主机操作系统,如

docker run -d --name simple2 -v //c/Users/src://usr/share/nginx/html -p 8082:80 ng1

Due to this issue : 由于这个问题

This is something that the MSYS environment does to map POSIX paths to Windows paths before passing them to executables. 这是MSYS环境在将POSIX路径传递给Windows路径之前将其传递给可执行文件的功能。

As the OP said:正如 OP 所说:

Official docker docs :官方码头文档:

Note: If you are using Docker Machine on Mac or Windows, your Docker daemon only has limited access to your OS X/Windows filesystem.注意:如果您在 Mac 或 Windows 上使用 Docker Machine,您的 Docker 守护程序只能有限地访问您的 OS X/Windows 文件系统。 Docker Machine tries to auto-share your /Users (OS X) or C:\\Users (Windows) directory - and so you can mount files or directories using Docker Machine 尝试自动共享您的 /Users (OS X) 或 C:\\Users (Windows) 目录 - 因此您可以使用挂载文件或目录
docker run -v /Users/:/ ... (OS X) docker run -v /Users/:/ ... (OS X)
or或者
docker run -v /c/Users/:/ docker run -v /c/Users/:/

But if you want access to other directories, you need to add a new shared folder to the virtual box settings (Settings > Shared Folders > Add share).但是如果你想访问其他目录,你需要在虚拟盒子设置中添加一个新的共享文件夹(设置>共享文件夹>添加共享)。

Add there a new share (only possible when you stop the vm before, docker-machine stop :在那里添加一个新共享(仅当您之前停止 vm 时才可能, docker-machine stop

path C:\Projects
name c/Projects
autoMount yes

Or edit directly the vbox configuration file或者直接编辑vbox配置文件
C:\\Users\\<username>\\.docker\\machine\\machines\\default\\default\\default.vbox

Add there into <SharedFolders> the line添加到<SharedFolders>

<SharedFolder name="c/Projects" hostPath="\\?\c:\Projects" writable="true" autoMount="true"/>

Restart the machine:重启机器:

docker-machine stop
docker-machine start

Now, it's possible to mount also directories with the base C:\\Projects现在,还可以使用基础C:\\Projects挂载目录

docker run -v //c/Projects/myApp://myApp <myImage>

For anyone using docker ~> 1.12 and faces this issue. 对于任何使用docker~> 1.12并面临此问题的人。 I spent 30min trying to figure it out until i realized you have to specifically share a drive first via docker settings, see: https://docs.docker.com/docker-for-windows/#/shared-drives 我花了30分钟试图搞清楚,直到我意识到你必须先通过docker设置专门共享一个驱动器,请参阅: https//docs.docker.com/docker-for-windows/#/shared-drives

如果您只是想访问本地驱动器,MINGW32 Docker Toolbox终端会将每个驱动器的根目录放在/<drive-letter> ,因此驱动器C:\\将位于/c/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM