This page will introduce how to install Docker in WSL. And all tools such as docker-cli, maven-docker-plugin or IDEs are able to connect to docker engine no matter from Windows or WSL.
Since Sep. 2022, WSL supports systemd. So you can install Docker in WSL like how you install in a normal Ubuntu.
Edit /etc/wsl.conf
and add below lines:
[boot]
systemd=true
And run wsl.exe --shutdown
to restart WSL.
note: Please make sure you've upgraded to latest WSL which supports systemd. For more details, you can visit:
Systemd support is now available in WSL!
Install Docker following the official instruction:
Install Docker Engine on Ubuntu
In order to access dockerd in Windows host, we need to expose dockerd in a TCP socket.
docker.service.d
foldermkdir -p /etc/systemd/system/docker.service.d/
vi /etc/systemd/system/docker.service.d/tcp.conf
And add/update lines:
[Service]
ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2375 --containerd='/run/containerd/containerd.sock'
sudo systemctl daemon-reload
sudo systemctl restart docker
You can go to this page if you need more explanation:
Install docker-cli without Docker Desktop
Environment variable DOCKER_HOST
indicates where the dockerd is. Most of the tools respect to this environment variable, including docker-cli, maven-docker-plugin, or IntelliJ IDEA.
Set DOCKER_HOST
to "tcp://localhost:2375" in your Windows user environment variable. That will be all.