Table of Contents
- NOTE
- PRE-REQUIETIES
- CONFIGURE USER POLICY
- ENABLE DOCKER TO AUTO-BOOT
- CONFIG HTTP PROXY (IF NEEDED)
- TRY DOCKER
This is the guide for WSL2 with Ubuntu distro. Before you start,
check your WSL distro version with
wsl --list -v, and it will show the VERSION with 2
if correct.
And to start systemd of WSL2, just edit the /etc/wsl.conf,
and add the configuration bellow. (You can use sudo vim /etc/wsl.conf)
[boot]
systemd=true
After the configuring, terminate the WSL2 server with wsl --shutdown ( or wsl --terminate <your distro name>)
and restart it. Then you can check if the systemd is running with
systemctl --no-pager status user.slice > /dev/null 2>&1 && echo 'OK: Systemd is running' || echo 'FAIL: Systemd not running'Install pre-requieties for docker:
sudo apt update && sudo apt upgrade
sudo apt install --no-install-recommends apt-transport-https ca-certificates curl gnupg2IMPORTANT: And then configure the iptables:
sudo update-alternatives --set iptables /usr/sbin/iptables-legacy
sudo update-alternatives --set ip6tables /usr/sbin/ip6tables-legacyNow we can install docker.
First we need to update the apt source for docker.
. /etc/os-release # load env vars form os-release
curl -fsSL https://download.docker.com/linux/${ID}/gpg | sudo tee /etc/apt/trusted.gpg.d/docker.asc
echo "deb [arch=amd64] https://download.docker.com/linux/${ID} ${VERSION_CODENAME} stable" | sudo tee /etc/apt/sources.list.d/docker.list
sudo apt updateAnd then just install it with apt:
sudo apt install docker-ce docker-ce-cli containerd.ioWe need add the current user in docker group manually.
sudo usermod -aG docker $USERTo confirm the change worked, close the terminal tab and open a new Ubuntu tab, then run:
groups | grep dockerYou should see docker in the content. And then terminate the WSL2 again (wsl --shutdown).
Finally, use:
sudo systemctl enable docker.serviceor:
sudo service docker startIt can be checked via:
systemctl list-units --type=serviceAnd you should see docker.service is not red, and is with active and running states.
If you need add proxy for docker daemon, just add the Systemd configure:
sudo mkdir -p /etc/systemd/system/docker.service.d
sudo vim /etc/systemd/system/docker.service.d/http-proxy.confand add these lines:
[Service]
Environment="HTTP_PROXY=http://<Your Proxy IP or Domain>:<port>"
Environment="HTTPS_PROXY=http://<Your Proxy IP or Domain>:<port>"Then restart your Docker service with new config:
sudo systemctl daemon-reload
sudo systemctl restart docker And check the new env var with:
sudo systemctl show --property=Environment dockerYou should see something like:
Environment=HTTP_PROXY=http://<Your Proxy IP or Domain>:<port> HTTPS_PROXY=http://<Your Proxy IP or Domain>:<port>You can try docker to see if it can connect to the dockerd:
docker run --rm hello-worldRefs: