Why I need this

I use Podman as my primary container tool, but many of the tools integrate with container work with Docker as default or the only choice, e.g. AWS SAM CLI, act. Due to these tools having great help on productivity, I started to study how to make Podman and Docker work together. Since Docker Desktop is only free for open-source projects, this post aims to install the Docker engine and use Docker CLI to operate Docker.

Pre-condition

This post assumes you already installed Podman and want to install Docker then. Follow the steps below to setup:

  1. Make sure WSL version is version 2

wsl --set-default-version 2

  1. Update WSL to the latest

wsl --update

  1. Choose a OS to host Docker, here we’ll going to use the latest Ubuntu

wsl -t Ubuntu-22.04

  1. Export the OS, since we’ll going to change the default storage, if you are fine with the default location please jump to the step 7.

wsl --export Ubuntu-22.04 {new path}\Ubuntu-22.04.tar

  1. Unregist the OS we just installed

wsl --unregister Ubuntu-22.04

  1. Regist at the new location

wsl --import Ubuntu-22.04 {new path}\Ubuntu-22.04 {new path}\Ubuntu-22.04.tar

  1. Enter to the OS we just installed

wsl -d Ubuntu-220.4 --user {your_user_name}

  1. Update the packages
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

# Add the repository to Apt sources:
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt-get update
  1. Install Docker engine

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Once the install finished, we are almost there, just in case we can check if we can invoke Docker in Ubuntu

sudo docker run hello-world

Docker engine settings

Check the wsl.conf settings in Ubuntu

cat /etc/wsl.conf

Make sure you have the following setting, if no please setup for it.

1
2
3
[boot]
systemd=true
command=sudo service docker start

We can now successfully operate Docker in Ubuntu but not in Windows (the host OS). To operate Docker via Windows, we need to move forward and add more settings.

sudo mkdir -p /etc/systemd/system/docker.service.d/

sudo vi /etc/systemd/system/docker.service.d/tcp.conf

Add following content:

1
2
3
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2377 --containerd='/run/containerd/containerd.sock'

The first ExecStart= is left blank; this is meaningful. It resets ExecStart= to avoid an error when executing. If you encounter an error message like the one below, please leave this blank in the settings:

docker.service: Service has more than one ExecStart= setting

Restart WSL after you finished.

1
2
wsl -t Ubuntu-22.04
wsl -d Ubuntu-22.04 --user {your_user_name}

Then restart Docker

1
2
sudo systemctl daemon-reload
sudo systemctl restart docker

Check service’s status

sudo service docker status

Host (Windows) settings

Back to Windows

1
scoop install main/docker

We install Docker but no need it run as server

Add new environment variable

1
[Environment]::SetEnvironmentVariable('DOCKER_HOST', 'tcp://localhost:2377', 'User')

Attention

We use port 2377 rather than default 2375 just because of the Podman use it as default too.

Reference