Windows volume mapping works only from home directory
In Windows, the Getting Started example works correctly only if the working directory is under the user's home directory (C:\users\username). Otherwise, it fails with the message:
python: can't open file 'app.py': [Errno 2] No such file or directory
which occurs because the /code directory is empty in the container.
The example Dockerfile is:
FROM python:2.7
ADD . /code
WORKDIR /code
RUN pip install -r requirements.txt
CMD python app.py
and docker-compose.yml contains:
volumes:
- .:/code
A standard Docker build produces a working container (that is, /code/app.py exists) regardless of the working directory. However, docker-compose up creates a working image only if run from C:\users\username or one of its subdirectories.
Yes, this is because Docker Machine only mounts that one shared folder by default. There's nothing we can do about this in Compose.
@dnephin If I take docker-compose out of the picture by running:
docker build -t web .
docker run web
the container starts without error and I can exec a bash shell that shows the directory:

Note that the example above is running outside the home directory. So there is something about the interface between docker-compose and docker-machine that's causing this error.
There is no volume in that example. If you were to use docker run -v $PWD:/code you'd have the same problem.
You can remove the volumes: ... from the compose file to get it working with compose as well.
Thanks! You are correct - removing volume makes it work. So I'd suggest that you update the Getting Started example to eliminate the Volume specification (or at the least, include a warning about this problem).
The volume config is important, as it lets you edit the code and see changes immediately, but we don't actually demonstrate that.
There was a suggestion long ago to add the volume config in a separate step after getting the app running, and demonstrating the benefits. I still think that'd be a good change, and you're right that we should also warn about mounting issues.
Separate step would be nice. That's what I ended up doing in a project that uses docker-compose for local dev environment, since not everyone has similar mountings but at least they can get the thing running immediately and if/when they need the live updates, they can see step n+1.
So there is no way around it? I tried mounting manually directory on other partition:
docker-machine.exe stop default
VBoxManage.exe sharedfolder add default --name "d/projects" --hostpath "D:\projects"
VBoxManage.exe showvminfo default | grep -i share -A4
docker-machine.exe start default
docker-compose up -d
// did not work
docker run -it -v "//d/projects:/d/projects" nginx /bin/sh
// did work to some extent
Hoping docker-compose will pick up on that automatically. But not only he didn't but also docker machine did mount only like 1 directory in projects ( the directory with docker files and also not all of them )
There isn't a way to make it work?
have you shared the drive containing the project directory in the docker settings? (see shared drive section here)
Once I'd done that I was able to run the Getting Started tutorial fine.
Here's a workaround for volumes outside of C:\Users. I'm on Win8.1, Docker Machine 0.7.0, no git bash. Add a shared folder and mount it inside the VM:
cd d:\my-project
vboxmanage sharedfolder add default --name my-project --hostpath "%cd%" --transient
docker-machine ssh default "sudo mkdir -p /d/my-project"
docker-machine ssh default "sudo mount -t vboxsf -o defaults,uid=`id -u docker`,gid=`id -g docker` my-project /d/my-project"
docker-compose up
Notes:
- Add
--readonlyto thevboxmanage sharedfoldercommand to create a read-only share - If
vboxmanageis not in yourPATH, try"%VBOX_MSI_INSTALL_PATH%\vboxmanage" - Replace
defaultwith%DOCKER_MACHINE_NAME%if necessary - You have to do these steps for every project
You might want to give the Docker for Windows beta a try - it uses a different approach for file syncing and doesn't have the C:\Users restriction.
Made a tool for it: docker-share. Give it a spin, when Docker for Windows is not an option for you. In its simplest form, the workflow is:
docker-machine start
@FOR /f "tokens=*" %i IN ('docker-machine env') DO @%i
cd my-project
docker-share mount -t
docker-compose up
I'm also having this problem in Windows 10. I'm running Docker for Windows (latest, 1.12.0-rc4-beta19) to no avail. I can ADD files but I cannot mount volumes. My project is in a subdirectory under C:\Users\me\Whatever\DockerProject. Would love to see this resolved!
@wulftone I am using Windows 10 too. I executed "docker inspect" and found the volume was mounted but the error still came out.
Finally I resolved by going to settings and set set Shared Drives. I hope it can help!

As I also still see these problems with devs using Windows, I came over https://forums.docker.com/t/volume-mounts-in-windows-does-not-work/10693/105 and it seems this still is a problem and only working for some users, for others it does work after fiddling around with firewall, security policies etc and for others it just doesnt work
@klawhk Thank you. That solved it for me. :)
oh a little update: for me the problems were because of a firewall integrated in AV (AntiVirus), so shut that OFF. Windows Firewall itself doesnt seem to cause problems tho.
The above workaround comment by @vweevers works great. When in doubt use docker inspect to find the mounted folders. I just mounted the entire project folder and that works fine.
thank you @vweevers , great tool.
by me it still automounts c:\users even though it is says in shared drives c how does one convince it to share c:\
I think this issue could be much more simply resolved by some more error handling in the docker-compose up command. If there was a way to inform the user (I guess info vs error) that the volume mount in windows using docker toolbox did not work because folder xyz does not exist (and then display where docker-compose is looking) would solve 99% of the problem. I know that much of my time was spent thinking it was something with the container I was using rather than not using my c:\Users\ directory even after I read the documentation. If I had seen in the console log that the mounting was from c:\Users I probably would have worked forward from there...or even to update the shared folders in VirtualBox.