Skip to content

Docker Share drive mount using docker-machine

Here, In this tutorial, I am going to show how to mount the drive other than the default c:\Users drive in Docker. This is will be helpful if you are using Docker toolbox using VirtualBox.

I have already installed the docker toolbox. I have a Project in my E drive. I will share this entire drive in Docker so that our container can access it. This is very useful if you want to instantly update the file in the docker container instead of always building the image on each edit in the files. Very useful during the development phase.

First, Stop the Docker machine if it’s running. Use below command:

docker-machine stop

Now, add a new shared folder in the VirtualBox MachineĀ for Docker. Generally, its name is “default”. Like the below image.

Now start the Docker machine by using below command:

docker-machine start

Now go inside the Docker Machine by this command:

docker-machine ssh

Here we need to create a new folder in the root of the project. I will give it the same name as “e”, you can name it anything. Use below command for this purpose:

docker@default:~$ cd /
docker@default:/$ mkdir e

Now, we can mount the shared folder using the below command:

docker@default:/$ sudo mount -t vboxsf -o uid=1000,gid=50 e /e

To double check, if it’s successfully mounted, you can check if the mounted directory list all the files from your host machine, use below command:

docker@default:/$ cd /e
docker@default:/e$ ls

It should list the files. if yes, then it’s correctly mapped.

Now you can run the container, and you can see your host machine folder project content is used by the container.

$ docker run -p 8080:80 --name nameyouwanttogive -v /e/Projects/phpapp:/var/www/html image

Here, my project files are in E:\Projects/phpapp, and the image I am using is for Apache which copies it to /var/www/html directory in the container.

Be First to Comment

Leave a Reply

Your email address will not be published.