How to use --volume option with Docker Toolbox on Windows?

This is an improvement of the selected answer because that answer is limited to c:\Users folder. If you want to create a volume using a directory outside of c:\Users this is an extension.

In windows 7, I used docker toolbox. It used Virtual Box.

  1. Open virtual box
  2. Select the machine (in my case default).
  3. Right clicked and select settings option
  4. Go to Shared Folders
  5. Include a new machine folder.

For example, in my case I have included:

**Name**: c:\dev
**Path**: c/dev
  1. Click and close
  2. Open "Docker Quickstart Terminal" and restart the docker machine.

Use this command:

$ docker-machine restart

To verify that it worked, following these steps:

  1. SSH to the docker machine.

Using this command:

$ docker-machine ssh
  1. Go to the folder that you have shared/mounted.

In my case, I use this command

$ cd /c/dev
  1. Check the user owner of the folder. You could use "ls -all" and verify that the owner will be "docker"

You will see something like this:

docker@default:/c/dev$ ls -all
total 92
drwxrwxrwx    1 docker   staff         4096 Feb 23 14:16 ./
drwxr-xr-x    4 root     root            80 Feb 24 09:01 ../
drwxrwxrwx    1 docker   staff         4096 Jan 16 09:28 my_folder/

In that case, you will be able to create a volume for that folder.

You can use these commands:

docker create -v /c/dev/:/app/dev --name dev image
docker run -d -it --volumes-from dev image

or

docker run -d -it -v /c/dev/:/app/dev image

Both commands work for me. I hope this will be useful.


If you are looking for the solution that will resolve all the Windows issues and make it work on the Windows OS in the same way as on Linux, then see below. I tested this and it works in all cases. I’m showing also how I get it (the steps and thinking process). I've also wrote an article about using Docker and dealing with with docker issues here.

Solution 1: Use VirtualBox (if you think it's not good idea see Solution 2 below)

  • Open VirtualBox (you have it already installed along with the docker tools)
  • Create virtual machine
  • (This is optional, you can skip it and forward ports from the VM) Create second ethernet card - bridged, this way it will receive IP address from your network (it will have IP like docker machine)
  • Install Ubuntu LTS which is older than 1 year
  • Install docker
  • Add shared directories to the virtual machine and automount your project directories (this way you have access to the project directory from Ubuntu) but still can work in Windows
  • Done

Bonus:

  • Everything is working the same way as on Linux
  • Pause/Unpause the dockerized environment whenever you want

Solution 2: Use VirtualBox (this is very similar to the solution 1 but it shows also the thinking process, which might be usefull when solving similar issues)

  • Read that somebody move the folders to /C/Users/Public and that works https://forums.docker.com/t/sharing-a-volume-on-windows-with-docker-toolbox/4953/2
  • Try it, realize that it doesn’t have much sense in your case.
  • Read entire page here https://github.com/docker/toolbox/issues/607 and try all solutions listed on page
  • Find this page (the one you are reading now) and try all the solutions from other comments
  • Find somewhere information that setting COMPOSE_CONVERT_WINDOWS_PATHS=1 environment variable might solve the issue.
  • Stop looking for the solution for few months
  • Go back and check the same links again
  • Cry deeply
  • Feel the enlightenment moment
  • Open VirtualBox (you have it already installed along with the docker tools)
  • Create virtual machine with second ethernet card - bridged, this way it will receive IP address from your network (it will have IP like docker machine)
  • Install Ubuntu LTS which is very recent (not older than few months)
  • Notice that the automounting is not really working and the integration is broken (like clipboard sharing etc.)
  • Delete virtual machine
  • Go out and have a drink
  • Rent expensive car and go with high speed on highway
  • Destroy the car and die
  • Respawn in front of your PC
  • Install Ubuntu LTS which is older than 1 year
  • Try to run docker
  • Notice it’s not installed
  • Install docker by apt-get install docker
  • Install suggested docker.io
  • Try to run docker-compose
  • Notice it’s not installed
  • apt get install docker-compose
  • Try to run your project with docker-compose
  • Notice that it’s old version
  • Check your power level (it should be over 9000)
  • Search how to install latest version of docker and find the official guide https://docs.docker.com/install/linux/docker-ce/ubuntu/
  • Uninstall the current docker-compose and docker.io
  • Install docker using the official guide https://docs.docker.com/install/linux/docker-ce/ubuntu/
  • Add shared directories to the virtual machine and automount your project directories (this way you have access to the project directory from Ubuntu, so you can run any docker command)
  • Done

This is actually an issue of the project and there are 2 working workarounds:

  1. Creating a data volume:

    docker create -v //c/Users/myuser:/myuser --name data hello-world
    winpty docker run -it --rm --volumes-from data ubuntu
    
  2. SSHing directly in the docker host:

    docker-machine ssh default
    

    And from there doing a classic:

    docker run -it --rm --volume /c/Users/myuser:/myuser ubuntu