DEV Community

Zaw Htut Win
Zaw Htut Win

Posted on

How to run Docker CE + WSL2 in Windows 11

Actually when you install WSL in Windows 11, WSL2 is selected by default.

First update your packages

sudo apt-get update

Then install the docker community edition and it's related packages

sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

add your user to the docker group

sudo usermod -aG docker $USER

Then restart your terminal.

Then run dummy container called hello-world which is non-existence.


docker run hello-world

You will likely to see

Unable to find image 'hello-world:latest' locally

This is because DNS blocks the Dockers. So use this command


echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf

Then run this command again.


docker run hello-world

Then you might see something like


Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: failed to resolve reference "docker.io/library/hello-world:latest": failed to authorize: failed to fetch anonymous token: Get "https://auth.docker.io/token?scope=repository%3Alibrary%2Fhello-world%3Apull&service=registry.docker.io": net/http: TLS handshake timeout

Don't worry it's easy. It's because of the MTU size. WSL use the Virtual Switch and it's Maximum Transmission unit is so big that the connection was timeout. So make it lower. We will set it to 1400


sudo ip link set dev eth0 mtu 1400

Then we will run the command again


docker run hello-world

Viola!

Top comments (0)