22

I am a beginner with docker and I am using a windows machine. But I have a problem mounting files using volumes. The documentation says the following thing about mount files on OSX and 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. 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/<path>:/<container path> ... (OS X) or docker run -v /c/Users/<path>:/<container path ... (Windows). All other paths come from your virtual machine’s filesystem.

I have a small nginx 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

enter image description here

Creating a container with a volume

My windows host directory

enter image description here

Creating the docker container with -v option

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

docker inspect ng1

enter image description here

What is wrong when I am creating a docker container with a volume?

Thanks.

afym
  • 532
  • 2
  • 6
  • 22
  • Are you running container from outside boot2docker VM? – hassansin Oct 24 '15 at 01:20
  • Since you are using `Windows` and as you said you are a beginner in docker , i would like to suggest you to please look at [Kinematic](https://docs.docker.com/kitematic/userguide/) once. Its a lucid way to understand **mounting of volumes**, **manage containers** etc.. i hope it helps. :) Cheers – chanakya devraj Oct 24 '15 at 19:54
  • Just realize that even you got correct mounting config, **docker inspect ng1** will remain to show **"Volumes" { "/usr/share/nginx/html": {}}** – 689 Apr 30 '16 at 15:55

4 Answers4

37

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.

Stanislav
  • 27,441
  • 9
  • 87
  • 82
  • As a side note for Windows, if you had mounted the volume without specifying the source, the Source path that `docker inspect` reports is in the VM running docker, which you can access with `docker-machine ssh` or by accessing the VM through VirtualBox or whichever provider is in use. – Spencer Williams Feb 14 '16 at 08:02
4

As the OP said:

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. 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/:/

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:

path C:\Projects
name c/Projects
autoMount yes

Or edit directly the vbox configuration file
C:\Users\<username>\.docker\machine\machines\default\default\default.vbox

Add there into <SharedFolders> the line

<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

docker run -v //c/Projects/myApp://myApp <myImage>
Cadoiz
  • 1,446
  • 21
  • 31
jeb
  • 78,592
  • 17
  • 171
  • 225
3

For anyone using docker ~> 1.12 and faces this issue. 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

olive_tree
  • 1,417
  • 16
  • 23
0

If you're simply looking to access a local drive, the MINGW32 Docker Toolbox terminal puts the root of each drive in /<drive-letter>, so drive C:\ will be at /c/

James Gentes
  • 7,528
  • 7
  • 44
  • 64