Fixing Docker to run smooth on Windows

Few months ago I’ve described why Windows is awesome for software development now. However there were still a few major flaws and most of them were related to Docker for Windows:

  1. (NOTE: this issue is not relevant as of May 2019) Native Windows Docker is quite unstable, I had to reset its settings to default or even reinstall Docker completely every week or two.
  2. Native Windows Docker uses Hyper-V, which makes impossible using both Docker and VMWare/Virtualbox at the same time. Also it does not work on Windows Home edition.

Today we’ll go through solutions for these issues.

Docker Toolbox

Docker Machine is the heart of Docker Toolbox

Before native Windows Docker there was a cross-platform solution called Docker Toolbox. It is a docker machine (docker engine, that could run on different back ends) with bundled VirtualBox back end running minimalist Linux distribution, a set of additional tools.

Docker team tells following about Docker Toolbox:

Legacy desktop solution. Docker Toolbox is for older Mac and Windows systems that do not meet the requirements of Docker for Mac and Docker for Windows. We recommend updating to the newer applications, if possible. Docker Toolbox provides a way to use Docker on Windows systems that do not meet minimal system requirements for the Docker for Windows app.

But as of July 2018 it is just not true. After using Docker Toolbox for 3 months (and using native Windows Docker for a year) I can tell you for sure, Docker Toolbox is much more stable and flexible solution than Native Windows Docker. It just works!

But what’s wrong with Docker Toolbox?

There are few (easy to overcome) issues with Docker Toolbox I’ve encountered:

  1. It runs on virtual address (e.g. 192.168.99.100) instead of localhost.
  2. No UI to increase VM memory for Docker.
  3. Symlinks doesn’t work when mapping back to NTFS host volume. Especially painful when using NodeJS’s node_modules bin symlinks.

Fixing Docker Toolbox

Fortunately each of those issues is easily solvable.

Running on Localhost

Docker Toolbox uses VirtualBox and VirtualBox could map any ports of guest machines back to the host. So all we need to do is set this mapping up. There are 2 possible ways to do this: use console or VirtualBox GUI.

Let’s start with console way. Assuming your docker machine is called “default” and you want to map port 80 in your container to localhost:8888 you can run:

vboxmanage modifyvm default --natpf1 "nameformapping,tcp,,8888,,80"

or if the VM is running:

vboxmanage controlvm default natpf1 "nameformapping,tcp,,8888,,80"

Or just set it via GUI

Increasing VM Memory

By default Windows Docker dedicated 2Gb RAM, which is quite low. I’m using Elasticsearch in a few projects and it alone takes more than 1Gb of RAM.

And solutions is quite straightforward. It requires 2 steps. First: remove existing Docker virtual machine:

docker-machine rm default

Second: re-create virtual machine with amount of RAM, CPU cores or disk space you want:

docker-machine create -d virtualbox --virtualbox-cpu-count=2 --virtualbox-memory=4096 --virtualbox-disk-size=50000 default

Restart Docker and the issue if solved.

Symlinks on host share

Symlinks issue was the most tricky for me, however workaround was quite easy. Windows 10 already supports symlinks, but somehow this functionality is enabled only for administrators. So all you need to do is launching “Docker quickstart terminal” as Administrator each time you work with Docker and that’s it — symlinks are created with no problem.

What about Native Windows Docker?

I believe Docker team is working hard on native solution for Windows, which is definitely more user-friendly. Probably It’ll become de-facto standard in future, but for now I recommend no one to use it: Docker Toolbox is much more stable and does not require Hyper-V with its clear downsides.