2017-09-17

Running docker in Ubuntu on Windows 10 Home Edition

With Ubuntu running in WSL on Windows 10, I want it to be as close to a "real" Ubuntu installation as possible. One of the shortcomings with WSL is that it doesn't allow you to run docker. apt install docker works as expected, and running docker will give you the familiar menu, but docker ps is sufficient to break the spell.

$ docker ps
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

It turns out that you can run the docker client commands in WSL ubuntu, but you can't run the docker service through WSL. The trick is to run docker in Windows, and get your client in WSL Ubuntu to talk to that.

These days, there is Docker for Windows which uses Microsoft Hyper-V in Windows 10, but since my laptop only run Windows 10 Home Edition, I installed the older Docker Toolbox, which is based on VirtualBox. At first, I installed a brand new VirtualBox, and then intalled Docker Toolbox (which also includes VirtualBox). This caused a networking problem, but after I deinstalled both Docker and VirtualBox, and ran the Docker Engine installer again so that it could install its preferred version of VirtualBox, it worked fine. I didn't include Kitematic, marked alpha, in the install.

The trick now, is to get the WSL Ubuntu docker client to communicate with the server in the VirtualBox. To do this, you need to define three environment variables:

export DOCKER_HOST=tcp://XXX:2376  
export DOCKER_TLS_VERIFY=1
export DOCKER_CERT_PATH=/mnt/c/Users/XXX/.docker/machine/certs/

 Of course, you should replace the XXX part in the host and cert variables. DOCKER_HOST should be the same as you have in Windows. I assume you know your Windows home directory...

Having done this much, enables me to do:

$ docker run -it alpine sh/ 
#
The obvious remaining problem is mounting volumes. Even if I run this in WSL Ubuntu, the docker service runs in a different environment, with a different view of the file system. I assume that provided directories must be avilable from the Windows system, and presented with paths that make sense in Windows...

I suspect there will be more complications, but there is basic operation at least. :-)




No comments:

Post a comment