以下是一些写给自己的备忘录。
关于 Quadlet 介绍 1
如何设置开机自动启动。2
The services created by Podman are considered transient by systemd, which means they don’t have the same persistence rules as regular units. In particular, it is not possible to systemctl enable them in order for them to become automatically enabled on the next boot.
To compensate for this, the generator manually applies the [Install] section of the container definition unit files during generation, in the same way systemctl enable does when run later.
For example, to start a container on boot, add something like this to the file:
[Install]
WantedBy=default.target
从 Docker 迁移到 Rootless Podman 时最常遇到的权限挑战。
- Docker Compose:直接以 root 权限运行 Docker 守护进程,容器内的用户(UID 1000)就是主机上的用户(UID 1000)。
- Rootless Podman:为了安全,将容器内的用户(UID 1000)“映射”成了主机上一个高位的、无特权的 UID(比如我们之前看到的
100999)。 当 Rootless Podman 容器看到那些所有者为1000的旧文件时,它会认为“这不是我的文件”,因此没有权限修改。
解决方案:运行时保留主机 UID (--userns=keep-id)
这是最灵活、最无损的方案。它的原理是告诉 Podman:“对于这个容器,请不要使用复杂的 subuid 映射,直接把我的主机用户(wogong,UID 1000)映射为容器内的用户(UID 1000)。”
优点:
- 无需修改任何旧文件,数据保持原样。
- 可以无缝地在 Docker Compose 和 Rootless Podman 之间切换。
- 操作简单,只需在运行时添加一个参数。
具体操作方法:对于 podman run 命令:** 在您的命令中加入 --userns=keep-id 参数即可。
podman run -it --rm \
--name freqtrade-debug \
--userns=keep-id \
-p 10.0.0.2:8084:8080 \
-v /path/to/your/old_user_data:/freqtrade/user_data \
docker.io/freqtradeorg/freqtrade:stable \
trade --config /freqtrade/user_data/config.json ...
links #
-
Run Podman Containers Under Systemd with Quadlet https://docs.oracle.com/en/learn/ol-podman-quadlet/index.html#introduction ↩︎
-
https://docs.podman.io/en/latest/markdown/podman-systemd.unit.5.html ↩︎