Skip to content

Commit bf3b60d

Browse files
committed
ops/container: More info about podman
Unqualified search registries; Socket; Quadlet and podlet
1 parent 4edaa52 commit bf3b60d

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

docs/ops/virtualization/container.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,10 +1714,56 @@ Docker 不是唯一的容器实现。OCI(Open Container Initiative)是 Linux
17141714
[Podman](https://podman.io/) 是红帽主推的容器方案,在 Fedora 和 RHEL 上自带。相比于 Docker,其最主要的特点是,没有 daemon,因此在一些操作上和 Docker 有显著的不同,例如:
17151715

17161716
- Podman 使用 rootless container 的方式让普通用户创建容器,而不是像 Docker 那样需要向用户授予与 root 等价的权限。
1717+
- 尽管 Docker 后续也提供了 rootless 的支持,但是从实际用户体验上,Podman 在 rootless 场景下仍然更易用一些。
17171718
- 由于 Podman 没有 daemon,因此设置容器自动启动等依赖于 systemd 的用户服务等功能。
17181719

17191720
Podman 提供了与 Docker 兼容的命令行工具,但是在一些细节设置上仍然会出现不同的情况。
17201721

1722+
!!! tip "配置容器镜像的默认 registry"
1723+
1724+
在 Docker 中如果没有指定镜像的 [registry](#registry),那么它就会默认以 `docker.io` 作为 registry。但是 Podman 不会这么做。[`/etc/containers/registries.conf.d/shortnames.conf`](https://github.com/containers/shortnames/blob/main/shortnames.conf) 会包含一些常用镜像的短命名与实际命名的映射(例如 `"debian" = "docker.io/library/debian"`),但是在实际使用时用户可能还是更习惯于 Docker 的行为。
1725+
1726+
可以添加以下配置文件:
1727+
1728+
```conf title="/etc/containers/registries.conf.d/unqualified-search-registries.conf"
1729+
unqualified-search-registries = ["docker.io"]
1730+
```
1731+
1732+
!!! tip "兼容使用 Docker API 的程序"
1733+
1734+
例如 `docker-compose` 等程序默认会连接 Docker 的 socket(`/var/run/docker.sock`),但是 Podman 默认不会监听这个 socket。为了提供支持,需要在系统或者用户 systemd session(取决于是否为 rootless)启动 `podman.service` 服务或 `podman.socket`(由 systemd 在收到连接后激活服务)。
1735+
1736+
Socket 默认在 `/run/podman/podman.sock` 或 `/run/user/<uid>/podman/podman.sock`(rootless)。对需要使用 Docker API 的程序,一般设置 `DOCKER_HOST` 环境变量即可。仍然需要提醒的是,Podman 提供的是尝试兼容 Docker API 的实现,可能无法满足某些程序的需求。
1737+
1738+
!!! tip "配置 Podman 容器的自启动"
1739+
1740+
Podman 使用 [Quadlet](https://github.com/containers/podman/tree/main/pkg/systemd/quadlet) 为 systemd 环境提供自启动支持。Quadlet 是一个 systemd generator(位于 `/usr/lib/systemd/system-generators/podman-system-generator`)——会从 quadlet 文件生成 systemd 服务。Quadlet 文件的格式和 systemd 单元的配置很像:
1741+
1742+
```ini title="example.container"
1743+
[Container]
1744+
ContainerName=example
1745+
Image=docker.io/library/debian
1746+
PublishPort=127.0.0.1:1234:1234
1747+
Exec=sleep 1234
1748+
1749+
[Service]
1750+
Restart=always
1751+
1752+
[Install]
1753+
WantedBy=default.target
1754+
```
1755+
1756+
然后放在 `/etc/containers/systemd/` 或者 `~/.config/containers/systemd/`(rootless)即可。不过手写这个文件还是太麻烦了,可以使用 [podlet](https://github.com/containers/podlet) 帮我们代劳:
1757+
1758+
```shell
1759+
# 生成已有的某个容器的 quadlet
1760+
podlet -i generate container example
1761+
# 根据启动命令生成 quadlet
1762+
podlet -i podman run --name example -p 127.0.0.1:1234:1234 --restart=always docker.io/library/debian sleep 1234
1763+
```
1764+
1765+
有关配置文件格式,详情可参考 [podman-systemd.unit.5][podman-systemd.unit.5]。
1766+
17211767
### LXC
17221768

17231769
[LXC](https://linuxcontainers.org/lxc/introduction/) 是一个 low level 的容器工具,提供了一些底层的 API 与命令行工具。在实际使用中,用户一般不会直接使用 LXC 的工具,而是使用 LXC 的高层次封装工具;开发者也可以基于 LXC 自行开发工具。Proxmox VE 的容器支持就是基于 LXC 的封装,而 LXD 则是 Canonical 开发的基于 LXC 的工具。

includes/man.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
[gai.conf.5]: https://man7.org/linux/man-pages/man5/gai.conf.5.html
4949
[journald.conf.5]: https://www.freedesktop.org/software/systemd/man/latest/journald.conf.html
5050
[nsswitch.conf.5]: https://man7.org/linux/man-pages/man5/nsswitch.conf.5.html
51+
[podman-systemd.unit.5]: https://docs.podman.io/en/latest/markdown/podman-systemd.unit.5.html
5152
[resolv.conf.5]: https://man7.org/linux/man-pages/man5/resolv.conf.5.html
5253
[sd_notify.3]: https://www.freedesktop.org/software/systemd/man/latest/sd_notify.html
5354
<!-- begin slurm config files -->

0 commit comments

Comments
 (0)