Skip to content

Instantly share code, notes, and snippets.

@hakiri
Forked from ChristophShyper/wsl2-docker.md
Created November 17, 2020 12:21
Show Gist options
  • Save hakiri/4b82777756bb4b0e9adbdee270c8107c to your computer and use it in GitHub Desktop.
Save hakiri/4b82777756bb4b0e9adbdee270c8107c to your computer and use it in GitHub Desktop.
Instruction how to set up WSL2 to work with Docker in Windows 10

On Windows 10 build 18917 or higher

Win / Enable WSL and VMP

PowerShell:

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform

Win / Set WSL 2 as default

PowerShell:

wsl --set-default-version 2

Win / Install Linux distro from Microsoft Store

For example Ubuntu 18.04 LTS

Win / Optional: Install X11 server

For example VcXsrv.

WSL / Optional: Prepare for X11 on Windows

Add to ~/.bashrc (provide IP of your Windows host):

export DISPLAY=192.168.1.11:0

Win / Install Docker Desktop Edge

Download version 2.1.6.0 or search for latest.
Enable Enable the experimental WSL 2 based engine on General tab.
Enable your WSL distro on Resources tab.

WSL / Install Docker

Bash:

sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get install docker-ce
sudo gpasswd -a $USER docker
sudo mkdir /sys/fs/cgroup/systemd
sudo mount -t cgroup -o none,name=systemd cgroup /sys/fs/cgroup/systemd
sudo service docker start

WSL / Verify

Bash:

docker info
docker run hello-world
@hakiri
Copy link
Author

hakiri commented Sep 2, 2022

This is an old obsolete method.
You can download docker desktop for windows from the official web page and setup it's connection with wsl2 by checking the box under setting (after installing docker desktop for windows)

@michael-freidgeim-webjet

We are trying to use Docker Engine only to avoid Docker Desktop license fees.

@hakiri
Copy link
Author

hakiri commented Sep 2, 2022

You can install systemd and snap on wsl2 and install docker for Linux as for native Linux os. See here: https://github.com/arkane-systems/genie
And here: https://forum.snapcraft.io/t/running-snaps-on-wsl2-insiders-only-for-now/13033

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment