Work with Docker on Windows 7 has some specific differences. This technology targeted mostly to Linux platform. Use Mac OS or Windows is not recommended for production servers. But it is good for software or even hardware developers. For them it is important to have access from Docker container to local file system of host operating system. This way calls Bind Mounts. In the current article we will discuss this question and how it works on Windows 7 platform.
The Docker on Windows 7 has one additional layer between container and host operating system which is slow down the Docker speed, increase RAM expenses and isolate the Docker machine from host file system. Docker uses boot2docker system as Docker Machine. Boot2docker is a lightweight Linux distribution based on Tiny Core Linux made specifically to run Docker containers. Docker uses Virtual Box as Virtual Machine (VM). More details can be found on official Docker documentation page.
To run Docker containers I prefer to use Docker compose. Compose is a tool for defining and running multi-container Docker applications. The Docker on Mac OS and Linux does not require to use any VM as Windows 7 does. If I want to get access to files on host operating system from Docker container I need to make additional steps to make it.
Bind mounts is a way to do it. More details can be found on official Docker documentation page.
Unfortunately the official Docker documentation does not describe well all aspects of systems configuration. I spent half day to find the way to do it with Windows 7 as a host system. The Virtual Box Virtual Machine (VM) allow access only
C:\Users folder on the host operating system by default. Which is not very convenient cause my files I want to use in container may be located in other place and it is not a good idea by security reasons. That is why the better way just run the Virtual Box and change the sharing folders in setting to any place you prefer. Don’t forget to stop default VM before this procedure. The alias you give for new shared folder will be automatically mounted into Docker machine
root file structure. So, you can use in your container configuration
If you prefer to mount you shared folder to other place (
/mnt or something ) and make location in container configuration files more close to real infrastructure you can use such trick (see below).
Log In into the Docker machine via terminal and make the mounting point inside it. The problem is that if you do simple
mount command you will fail on your next restart your Docker machine. All your settings will be lost. That is why we need to create the special file which will command the Docker machine to mount it automatically.
In Docker Quickstart Terminal issue these commands:
$ docker-machine ssh
Next step is to change the directory and create the special file for this machine:
$ cd /mnt/sda1/var/lib/boot2docker/ $ sudo touch bootlocal.sh
Add this text to
bootlocal.sh shell file as
mkdir -p /mnt/myfiles mount -t vboxsf -o defaults,\ uid=`id -u docker`,\ gid=`id -g docker` myfiles /mnt/myfiles
Exit Docker machine and restart one:
$ docker-machine restart
Once it’s finished, log back in and verify it’s there:
$ docker-machine ssh $ ls /mnt/myfiles
You have to change the
docker-compose.yml file to make it work. Use the full
PATHs in your
volumes: section like this:
If you have better solution let me know. ;)
Be back soon. Have a good day…