WSL安装使用podman
2022-01-27 • 预计阅读时间 1 分钟
2022-01-27 • 预计阅读时间 1 分钟
由于wsl对systemd的支持有限,导致了最初使用docker的方式是要搭配Docker Desktop来使用.但是这个在Windows下各种稀奇古怪的问题导致了基本不可用.现在可以通过WSL安装podman来实现容器化.不过此处的限制,反而促成了使用podman成了最好的Windows容器服务.一个没有daemon,一个没有systemd.也不能说是互补,优点叠加了.
正式使用起来还是有些坑要注意的,特别是podman的容器默认是rootless的.建议如果你真的要root的容器,还是去玩docker-ce吧.
sudo pacman -S lxc arch-install-scripts podman shadow
/etc/subgid
wentao:100000:65536
此外/etc/subuid
wentao:100000:65536
echo "<h1>Hello, World</h1>" > index.html
podman pull docker.io/library/alpine:latest
podman run -p "8080:80/tcp" -v "$PWD:/usr/share/nginx/html:ro" nginx
在 host 上面可以通过 curl http://localhost:8080/index.html 查看效果.
这里由于wsl的限制,只能使用localhost, 不能用ip来访问.
解决办法:
$ rm -rf ~/.config/containers ~/.local/share/containers
podman system migrate
podman unshare cat /proc/self/uid_map
WARN[0000] Error initializing configured OCI runtime crun: no valid executable found for OCI runtime crun: invalid argument
0 1000 1
1 1000000 65536
具体的原因如下:
In the code pkg/rootless/rootless_linux.go:225 , if the newuidmap is missing, running podman system migrate won’t solve the “there might not be enough IDs available in the namespace” error. Because the error of cannot find newuidmap is discarded here.
if uids != nil {
err := tryMappingTool("newuidmap", pid, os.Geteuid(), uids)
uidsMapped \= err \== nil
}