IMLC.ME

Install Docker without Docker Desktop in WSL

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.

1. Turn on systemd in 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!

2. Install Docker

Install Docker following the official instruction:

Install Docker Engine on Ubuntu

3. Start dockerd in TCP

In order to access dockerd in Windows host, we need to expose dockerd in a TCP socket.

  1. create docker.service.d folder
mkdir -p /etc/systemd/system/docker.service.d/
  1. creat tcp.conf and add -H argument
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'
  1. restart dockerd
sudo systemctl daemon-reload
sudo systemctl restart docker

4. Download docker-cli in Windows

Download for Windows

You can go to this page if you need more explanation: Install docker-cli without Docker Desktop

5. Set DOCKER_HOST in Windows

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.

References

Configure the daemon with systemd