DEV Community

Jon Friesen
Jon Friesen

Posted on • Updated on

Sharing a Docker daemon with virtual machines

I was doing some testing on Windows for a command line tool last week that required a Docker daemon. I already had a Windows environment setup (minus Docker) on VirtualBox. The problem is VirtualBox does not handle nested virtualization well and my laptop was struggling with the virtual machines I needed already. Here are some easy steps to share a Docker daemon from your host machine with your VMs.

Host Machine

If your host machine is Windows, open your Docker settings and enable the "Expose Daemon on tcp://localhost:2375 without TLS" option and continue to the Virtual Machine section below. Linux users, continue reading:

  1. We need to edit the docker server configs, run sudo vim /lib/systemd/system/docker.service
  2. On the ExecStart line add -H tcp://0.0.0.0:2375 to the end and save
  3. Reload the service with systemctl daemon-reload && sudo service docker restart

To verify you can visit http://localhost:2375/version in a browser or curl http://localhost:2375/version and get JSON output of your Docker Engine version.

Virtual Machine

Configuring your virtual machine to use your host machines Docker daemon requires access to that machine via the network and setting an environment variable, the process is nearly identical on Linux and Windows:

Windows:
set DOCKER_HOST=<host_IP>:2375 && docker run hello-world

Linux:
DOCKER_HOST=<host_IP>:2375 && docker run hello-world

You can, of course, permanently set your DOCKER_HOST environment variable and user Docker as you would as if the daemon was running on your machine.

This post was original posted on my website: https://jonfriesen.ca/blog/sharing-a-docker-daemon-with-virtual-machines/

Top comments (0)