DEV Community

Stanislav Berkov
Stanislav Berkov

Posted on Edited on

Docker in Windows via WSL2, Ubuntu, docker

If you cannot use Docker Desktop you still can use docker in Windows via Linux and WSL2.

How to:

  • install WSL2,
  • enable mirrored networking mode for WLS2 (fix no connectivity when using CiscoVPN),
  • install Ubuntu 22.04,
  • install docker-ce on Ubuntu,
  • allow docker remote connection,
  • install Docker CLI in windows,
  • specify DOCKER_HOST.

As a result, you get docker command working in WSL2 and in Windows.

Mirrored networking mode for WSL2

Update config https://learn.microsoft.com/en-us/windows/wsl/wsl-config#configuration-settings-for-wslconfig:~:text=Windows%20to%20Linux.-,networkingMode,-%C2%B9%C2%B2
set networkingMode=mirrored

Install Docker

Follow instructions at https://docs.docker.com/engine/install/ubuntu/

Allow running docker command w/o root

sudo groupadd docker
sudo usermod -aG docker $USER
<reboot> or newgrp docker

Allow docker remote connections

Edit the file /etc/systemd/system/docker.service.d/override.conf by calling the command

systemctl edit docker

Change content to:

[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H fd:// --containerd=/run/containerd/containerd.sock
Enter fullscreen mode Exit fullscreen mode

Reload systemd and restart docker

systemctl daemon-reload
systemctl restart docker

Check that port is being listen

netstat -lntp | grep 2375

If not, check the docker logs

journalctl -xeu docker.service

In Windows install docker cli

winget install Docker.DockerCLI

Set environment variable

$env:DOCKER_HOST="tcp://localhost:2375"

You might get docker-credential-wincred not found error

Similar issue is discussed here https://github.com/docker/docker-credential-helpers/issues/24

Edit ~/.docker/config.json file to remove credsStore param.

Top comments (0)