Tel Map

Blog

Docker for Windows and Host Volumes

The container management system Docker is quite useful for running services or applications in a controlled, isolated environment. In a lot of situations it is also useful to have directories inside a docker container mapped to a local folder on the host system.
Especially in a development environment, where this setup allows you to modify source files (e.g. for a web application) in the host-volume directly in your IDE, and have the running docker service find those updated files immediately without the need for a deployment.

Although Docker containers usually run Linux binaries, there is also the “Docker Desktop” suite for Windows10 which allows you to execute Linux docker containers on a Windows system.

How does this work?

To run the Linux containers, Docker Desktop uses a virtual machine running a real Linux system. To be more precise, Docker Desktop requires the Windows10 virtualization feature “Hyper-V” to be active.
Any running Linux container is then executed inside the virtual machine. You can also view this VM by opening up the Hyper-V Manager application an you see the “MobyLinuxVM” created by Docker Desktop.

Mounted Host Volumes however are added to the virtual machine via a SMB/CIFS shared folder (like a network drive). In order to provide such a Host Volume you first need to “activate” this share on the Docker Desktop settings:

This will expose the selected drives as network shares on your computer, with the privileges of your current user.

So if you have any security concerns with this, you should not use this Host Volumes feature!

Example usage

To show you a simple example, we will start an Apache Httpd webserver and make it deliver some content we have in a local folder:

Now you can open you web browser at http://localhost and see the text “Hello World”. Everytime you edit the created file webserver-example/index.html the change will be directly reflected in the browser after refreshing the page.

Troubleshooting

As the Docker Desktop system relies on different parts of your system (SMB network shares, Hyper-V virtual machine, virtual network drives) it is quite prone to some errors.

Problem 1: The docker system can’t connect to the internet any more, and also ports can’t be mapped any more

This seems to happen, if you restart your Windows system with the “Fast Startup” option enabled, but the MobyLinuxVM virtual machine is still running. Apparently then Windows stores the VM state and restores it (incompletely) after the start.

In order to fix this, you have multiple options:

  • restart the Docker Desktop service after each restart (right-klick on the icon, and then select “Restart …”)
  • disable “Fast Startup” in the control panel of you windows machine
  • stop the Docker Desktop service before shutting down the computer

Problem 2: The host folder is not in sync with the Volume

Let’s say you have created a docker container with a volume mounted to a folder on the host system. But inside the docker container you can no longer see the files on your host, and also files created/edited inside the container in the volume are no longer shown on the host machine.

This can sometimes happen, if the CIFS connection between your host and the MobyLinuxVM breaks.

  • you changed your username of password
  • you changed your computer name
  • you changed something in the “network sharing” settings of the Windows system

If the problem persists event after a reboot of your machine, you can try to reset the credentials (that are used to establish the connection).

In the same settings dialog of Docker Desktop where you configure the Shared Drives, there is also a clickable Link “Reset credentials”. This will ask for your network login again, and store the new access credentials for the VM. You probably have to enable the Shared Drives again after clicking this.

If this does not help, you have finally the option to reset the Docker Desktop system to factory defaults. This includes wiping all your images and containers, so you should backup all your data and configuration first.
As the reset also removes and recreates the MobyLinuxVM, this helped me to recreate the Shared Drives with the correct connection, after the other options failed.

Leave a Reply

Your email address will not be published. Required fields are marked *