WSL 2 Alpine中的Docker,无Docker Desktop

8tntrjer  于 12个月前  发布在  Docker
关注(0)|答案(2)|浏览(129)

Docker under WSL1 without Docker Desktop is not possible,所以我试图通过遵循this article从 * WSL 2 Alpine中的 * 运行Docker。
然而,我没有那么幸运,让它工作。完全日志包括在下面。
有谁知道哪里出错了吗?
整个事情都是在alpine/v3.15下完成的(从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

字符串

vmdwslir

vmdwslir1#

你可以运行Docker守护进程,就像你链接到的博客文章中提到的那样:

sudo dockerd

字符串
然后切换到另一个WSL Alpine示例并运行Docker客户端命令。
但是要使用OpenRC Docker服务,您有两个选择。
首先,您可以启动OpenRC,然后手动启动Docker服务:

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


或者你可以将Docker服务添加到默认的运行级别(一次性),然后每当OpenRC在该运行级别启动时,它就会运行:
一次性:

rc-update add docker default


然后,使用默认的runlevel启动OpenRC,这也将运行Docker:

openrc default


实际上,似乎你唯一遗漏的是OpenRC没有首先初始化。通常情况下,这将在Alpine init期间完成,但WSL自己的/init正在运行。

aemubtdh

aemubtdh2#

我要指出两个方向。
第一个是快速简单的方法,切换到一个无守护进程的容器引擎,比如lxc或podman,并以无根的方式运行你的容器。
第二个是强制WSL像VM一样运行。这是通过编辑/etc/wsl.conf并添加以下内容来启动openrc init子系统来完成的:

[boot]
command="openrc default"

字符串
还可以通过/etc/network/interface添加环回设备:

auto lo
iface lo inet loopback


警告;
一个人必须进入wsl环境与--login.简单的wsl -d Alpine docker ...将不会有wsl执行一个 Boot 序列.然而,当一个人有一个登录shell然后后续的wsl -d Alpine docker ...命令将按照预期工作,因为openrc已经执行.
简单地说,将wsl视为 Package 器只在创建登录shell后才起作用,但在使用podman时就不是问题了。

相关问题