Skip to content

Instantly share code, notes, and snippets.

@peteristhegreat
Last active September 16, 2022 14:32
Show Gist options
  • Save peteristhegreat/4bcbca81ed68605e36cf56bb0fff2960 to your computer and use it in GitHub Desktop.
Save peteristhegreat/4bcbca81ed68605e36cf56bb0fff2960 to your computer and use it in GitHub Desktop.
Docker on WSL2, that works

Docker on WSL2, that works

https://dev.to/felipecrs/simply-run-docker-on-wsl2-3o8

Gotchas when I was installing docker this time around on Windows:

If you are looking at wsl, you install wsl initially from the admin prompt, and all the other commands are from your user prompt.

wsl -l -v  # works from user prompt, but empty on admin

If you install a distro from the Microsoft store, they download as wsl v1. You have to upgrade it with

wsl --set-version Ubuntu-22.04 2
#                 ^^^^^^^^^^^^ Distro name here

Docker installs into a WSL container pretty normally, EXCEPT:

iptables, nft gotcha

It will consistently fail due to iptables errors that you can find in the sudo cat /var/log/docker.log start daemon logs.

The errors look like

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

And the log file will have a line like:

nft mnl.c:60: Unable to initialize Netlink socket: Protocol not supported wsl

or

Running iptables --wait -t nat -L -n failed with message: `iptables/1.8.7 Failed to initialize nft: Protocol not supported`, error: exit status 1

The Fix

sudo update-alternatives --set iptables /usr/sbin/iptables-legacy

Autostart docker service

Add to the bottom of .bash_profile

if service docker status 2>&1 | grep -q "is not running"; then
    wsl.exe -d "${WSL_DISTRO_NAME}" -u root -e /usr/sbin/service docker start >/dev/null 2>&1
fi

Other noteworthy projects

https://github.com/slonopotamus/stevedore

https://container-desktop.io

https://github.com/abiosoft/colima

Opening ports...

https://stackoverflow.com/questions/61002681/connecting-to-wsl2-server-via-local-network

https://superuser.com/questions/1586386/how-to-find-wsl2-machines-ip-address-from-windows

https://stackoverflow.com/questions/63784906/firewall-blocking-wsl-2

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