Docker in WSL2

Starting Docker Automatically Inside WSL2

The package enables docker.service and containerd.service, but inside WSL2 6 that only matters when systemd 142,543 is the distribution's init, which /etc/wsl.conf controls:

systemd as PID 1 inside WSL2, and Docker's services enabledShell
cat /etc/wsl.conf
ps -p 1 -o comm=
systemctl is-enabled docker.service containerd.service
Output
[user]
default=dev
[boot]
systemd=true
systemd
enabled
enabled

With systemd=true, starting the distribution (a terminal tab or any wsl -d Ubuntu-26.04 command) boots systemd, which starts containerd 234,762 and Docker 514 . After editing wsl.conf, run wsl --shutdown in Windows and start again. A distribution without systemd can use command = "service docker start" under [boot] instead. WSL may stop a distribution nobody is using, and its containers with it; those started with --restart unless-stopped, like BookNest's PostgreSQL 1,289 , return with Docker. WSL2 forwards published ports, so http://localhost:3000 in a Windows browser reaches a container in the distribution, and wsl -d Ubuntu-26.04 docker ps works from PowerShell 55,538 with no Docker Desktop 514 .