There is not a lot of documentation for Docker on Windows, and even less on harnessing the power of volumes therein. If you are like me, you may have spent a lot of time scratching your head over why your volumes simply aren’t mounting. There are countless help requests scattering the Docker GitHub and its relatives, and equally as many “fixes” that simply do not work.
So I’m here to report what worked both times that this has been an issue for me.
When running your container, use
//x/ to reference your drive, where
x is your lowercase drive letter. To reference
C:\Users\admin\volume, you would use
Configure Oracle VirtualBox to have access to that folder. This is the important solution that is not well documented. Oracle VirtualBox, the virtual machine behind Docker Toolbox, does not have access to your folders by default. Mounting
C:\MyFolder\ does nothing until you’ve given VirtualBox access to that folder.
- Find VirtualBox on your machine and run it.
2. Right-Click the
default machine and choose Settings.
3. Choose the Shared Folders category and add a shared folder.
Give the folder name something convenient. It is what you will type when you mount it via
-v. Make it auto-mount and permanent.
In my case, if I
docker run --volume //d/docker/nginx:/etc/nginx, I will be binding the
/etc/nginx directory in my container to
D:\Program Files\Docker Toolbox\nginx. I am not suggesting you use the Docker Toolbox directory, as you can use any that you desire; I only used it as an example.
You may need to restart the default machine for your changes to take affect. You may do so by right-clicking it and choosing the Reset option.
Binding your volumes should now work.
If this solved your problem, feel free to give this article a clap. It’s quick, it’s easy, and it’s free!