Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker in WSL2 Alpine without Docker Desktop

Docker under WSL1 without Docker Desktop is not possible, so I'm trying to run Docker from within WSL2 Alpine by following this article.

However I'm not that lucky to get it working. Fully log included below.

Anyone know where thing went wrong please?

The whole thing is done under alpine/v3.15 (installed from https://apps.microsoft.com/store/detail/alpine-wsl/9P804CRF0395?hl=en-us&gl=US) --

Downloading : https://dl-cdn.alpinelinux.org/alpine/v3.15/releases/x86_64/alpine-minirootfs-3.15.0-x86_64.tar.gz

% apk del docker-cli docker-ce docker-openrc docker-compose docker
ERROR: No such package: docker-ce

% apk del docker-cli docker-openrc docker-compose docker
(1/17) Purging containerd-openrc (1.5.11-r2)
(2/17) Purging iptables-openrc (1.8.7-r1)
(3/17) Purging ip6tables-openrc (1.8.7-r1)
(4/17) Purging docker-openrc (20.10.16-r0)
(5/17) Purging docker (20.10.16-r0)
(6/17) Purging docker-engine (20.10.16-r0)
(7/17) Purging containerd (1.5.11-r2)
(8/17) Purging runc (1.1.2-r1)
(9/17) Purging ip6tables (1.8.7-r1)
(10/17) Purging tini-static (0.19.0-r0)
(11/17) Purging docker-cli (20.10.16-r0)
(12/17) Purging ca-certificates (20211220-r0)
Executing ca-certificates-20211220-r0.post-deinstall
(13/17) Purging libseccomp (2.5.2-r0)
(14/17) Purging iptables (1.8.7-r1)
(15/17) Purging libnftnl (1.2.1-r0)
(16/17) Purging libmnl (1.0.4-r2)
(17/17) Purging device-mapper-libs (2.02.187-r2)
Executing busybox-1.34.1-r3.trigger
OK: 11 MiB in 22 packages

% sudo apk add docker --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community
-ash: sudo: not found

% apk add docker --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community
fetch http://dl-cdn.alpinelinux.org/alpine/edge/community/x86_64/APKINDEX.tar.gz
(1/17) Installing ca-certificates (20211220-r0)
(2/17) Installing libseccomp (2.5.2-r0)
(3/17) Installing runc (1.1.2-r1)
(4/17) Installing containerd (1.6.4-r2)
(5/17) Installing containerd-openrc (1.6.4-r2)
(6/17) Installing libmnl (1.0.4-r2)
(7/17) Installing libnftnl (1.2.1-r0)
(8/17) Installing iptables (1.8.7-r1)
(9/17) Installing iptables-openrc (1.8.7-r1)
(10/17) Installing ip6tables (1.8.7-r1)
(11/17) Installing ip6tables-openrc (1.8.7-r1)
(12/17) Installing tini-static (0.19.0-r0)
(13/17) Installing device-mapper-libs (2.02.187-r2)
(14/17) Installing docker-engine (20.10.16-r0)
(15/17) Installing docker-openrc (20.10.16-r0)
(16/17) Installing docker-cli (20.10.16-r0)
(17/17) Installing docker (20.10.16-r0)
Executing docker-20.10.16-r0.pre-install
Executing busybox-1.34.1-r3.trigger
Executing ca-certificates-20211220-r0.trigger
OK: 238 MiB in 39 packages

% service docker restart
 * WARNING: docker is already starting

% service docker status
 * You are attempting to run an openrc service on a
 * system which openrc did not boot.
 * You may be inside a chroot or you may have used
 * another initialization system to boot this system.
 * In this situation, you will get unpredictable results!
 * If you really want to do this, issue the following command:
 * touch /run/openrc/softlevel

% touch /run/openrc/softlevel
touch: /run/openrc/softlevel: No such file or directory

% service openrc start
 * service: service `openrc' does not exist

% service docker-openrc start
 * service: service `docker-openrc' does not exist
like image 535
xpt Avatar asked Oct 27 '25 21:10

xpt


2 Answers

You could just run the Docker daemon as noted in the blog post you linked to:

sudo dockerd

Then switch to another WSL Alpine instance and run the Docker client commands.

But to use the OpenRC Docker service, you have two options.

First, you can start OpenRC and then start the Docker service manually:

openrc default
rc-service docker start # or service docker start

Or you can add the Docker service to the default runlevel (one-time), and then it will run whenever OpenRC is started in that runlevel:

One-time:

rc-update add docker default

Then, to start OpenRC with the default runlevel, which will also run Docker:

openrc default

Really, it seems the only thing you were missing is that OpenRC wasn't initialized first. Normally, that would be done during Alpine init, but WSL's own /init is running instead.

like image 108
NotTheDr01ds Avatar answered Oct 29 '25 15:10

NotTheDr01ds


Going to point out two directions.

First one is the quick and easy method. Switch to a daemonless container engine such as lxc or podman and run your containers as rootless.

Second one is forcing WSL to behave like a VM. This is done by editing /etc/wsl.conf and adding the following to start the openrc init subsystem:

[boot]
command="openrc default"

Also add a loop back device via /etc/network/interface:

auto lo
iface lo inet loopback

Caveate;

one has to enter into the wsl environment with --login. simple wsl -d Alpine docker ... will not have wsl execute a boot sequence. However after one has a login shell then subsequent wsl -d Alpine docker ... commands will work as expected since openrc has been executed.

Simply put, treating wsl as a wrapper only works after a login shell is created but not an issue when one uses podman.

like image 36
Dwight Spencer Avatar answered Oct 29 '25 17:10

Dwight Spencer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!