With that done, all we need to do is instruct the CLI under Bash to connect to the engine running under Windows instead of to the non-existing engine running under Bash, like this: $ docker -H tcp://0.0.0.0:2376 images The endpoint uses TLS, which means we have to set up the client on the WSL side to recognize the certificates that the Docker machine on the Windows side uses (thanks Alan for the tip!): export DOCKER_HOST=tcp://192.168.99.100:2376 // your Docker IPĮxport DOCKER_CERT_PATH=/mnt/c/Users/YOUR_USERNAME/.docker/machine/certs Running docker against an engine on a different machine is actually quite easy, as Docker exposes a TCP endpoint which the CLI can attach to.
Connect Docker on WSL to Docker on Windows But with one or two extra steps, we’ll get it all working. Is the docker daemon running?Ĭlearly unsatisfying. We haven’t created any images yet, so that’s fine.Ĭannot connect to the Docker daemon at unix:///var/run/docker.sock. docker images from PowerShell and from Bash:
The Windows installer helpfully created a Docker shortcut on the desktop and/or in the Start menu – use that to start the Docker engine. We now actually have the Docker engine installed on both Windows and the WSL, but it isn’t started on either.
There are instructions here for how to get the latest version. Of course, there’s also the option of downloading and extracting the binaries we’ll need, and put them somewhere in your PATH. Sudo add-apt-repository "deb $(lsb_release -cs) stable"
$ sudo apt-get install apt-transport-https ca-certificates curl software-properties-common Here’s what I did: # Install packages to allow apt to use a repository over HTTPS There’s a description for Ubuntu in general here, which works for the WSL as well, with the exceptions of some of the optional steps. To install Docker on the WSL, you’ll need to jump through a few more hoops.
You can now run docker -version from Bash, and you don’t even have to read the rest of this blog post :) Making it work on Windows 10 Anniversary Edition bashrc (and reload your environment) and you’re done! export PATH="$HOME/bin:$HOME/.local/bin:$PATH"Įxport PATH="$PATH:/mnt/c/Program\ Files/Docker/Docker/resources/bin" With Windows 10 Creators Update, accomplishing all of this has become a lot simpler, since it allows you to run Windows executables from Bash.
Shortcut: Install Windows 10 Creators Update Also, make sure hardware virtualization is enabled and Hyper-V is installed, lest the engine won’t start. To install the Docker engine on Windows, just go to and download the appropriate distribution. This also has the advantage that you can start a container from PowerShell and interact with it from Bash, or the other way around – in other words, your computer will still feel just like one machine. Instead, we’ll run the Docker Engine on Windows, and connect to it from Bash. Docker requires access to quite a of lot system calls which aren’t necessarily all implemented on Windows, so getting the engine running under the WSL is probably not so easy. The original title of this post was “Running Docker from Bash on Windows”, but that would have been a slight overstatement. And it’s always bugged me that I couldn’t get Docker working from Bash on Windows – until now. Personally, I love being able to choose between PowerShell, Bash or plain old cmd when I want to script something.
When the Windows Subsystem for Linux (WSL) – or, as most people even at Microsoft often refer to it – Bash on Ubuntu on Windows – was announced on Microsoft’s Build conference 2016, a world of new tools opened up to us Windows devs.