Almost a year ago I had issues setting up the shared volume on Windows machine, tried a few tutorials I found online but that did not help...
So I decided to share my experience.
First of all, we need Docker, here are installation instructions.
You can verify your installation by running this command:
and output should be similar to this:
Docker version 18.09.2, build 6247962 - OK, so we are ready to go.
Why do we need a shared volume?
We want to have a shared folder because then we can use our favorite code editor on our Windows machine and all changes will be automatically synced with our Docker container.
Let's enable the share drive option.
Open up Docker Desktop and click on Shared Drives:
On the right side select drive, you want to share, in my case, it is drive C, and finally, click on the Apply button.
Now, we can test this up, open up CMD and type this command:
docker run -it -v c:/docker:/docker alpine sh
please note that before running this command, for this purpose, I created a docker folder on my C drive.
The most important part of the command above is
-v c:/docker:/docker which is directory mapping,
c:/docker is a folder on the host machine, Windows,
:/docker is part regarding the container, you can name directory the way you want, a directory will be created automatically for you.
After the command is executed we will be in our Docker container:
Now we can see what do we have in this container by running:
so the docker directory is created for us. Now we can cd into it and create a new file to test whether syncing is working type:
cd docker && touch testfile1
as a result, we have a file created:
now we can check if folder on Windows is up to date:
Great! It is working.
Just to double-check, create one more file but this time on Windows:
now, check container:
It is working, nice!
This is all you need to do in order to utilize the sharing folder option between Windows as a host and a Docker container.
Thank you for reading!
Level up every day