Docker in Windows WSL 2

Xander Grzywinski
Jul 23 · 2 min read
Image credit to Ashley McNamara, source Gopher Repo

Hey everyone! Following up on my post on setting up a Docker and Kubernetes dev environment in WSL 1, I thought I’d share the process I went through for getting Docker installed now that WSL 2 is out and about! So far, switching to WSL 2 has been a HUGE improvement for me, the performance bumps were definitely not overstated :)

Step 1: Get WSL 2

Currently, WSL 2 is available to Windows insiders in the fast ring

Configure Windows insider program with the above settings.

Once you’ve setup the insider program with the above settings, you should be able to check for updates and get a build that supports WSL 2 (18917 or higher).

After you’re on a correct build, open up a PowerShell admin window and run:

Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform

After that, restart your computer (I know, I know…). Once you boot back up, you should be set to convert your WSL installation to WSL 2 with this command (replace <Distro> with the Linux distro you have installed) in PowerShell:

wsl --set-version <Distro> 2

For slightly more detailed instructions, you can refer to the official docs here!

Step 2: Install Docker

To install Docker, just open up a WSL 2 window (open PowerShell, or Windows Terminal and type wsl ) and run the following commands:

$ sudo apt-get remove docker docker-engine containerd runc $ sudo apt-get update$ sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common$ curl -fsSL | sudo apt-key add -$ sudo add-apt-repository "deb [arch=amd64] $(lsb_release -cs) stable"$ sudo gpasswd -a $USER docker

Lastly, since WSL 2 doesn’t use systemd, Docker won’t be able to start on it’s own. To start it, run:

$ sudo service docker start

That’s it! You should now be able to interact with the Docker daemon fully within WSL!

Xander Grzywinski

Written by

Site Reliability Engineer @ Microsoft | Ravenclaw

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade