2013 年 Docker 公司(當時叫 dotCloud)公開了 Docker 專案,把 Linux 上的 LXC (Linux Containers) 包裝成「開發者友善」的工具,使得 Docker 一詞幾乎成為「容器」的代名詞。 隨著 Docker 的普及,問題也慢慢浮現,Docker Engine 太龐大,runtime、CLI、Daemon、build、network、volume 等功能,全都綁在一起。 然後要用到容器的環境如 K8s,通通都要同捆全裝。 Docker 公司想商業化(Docker EE),但社群希望保持開源。
2017 時,Docker Engine 變成 Moby Project 進行 Docker Engine 的開源化重構,把原本 monolithic 的 Docker Engine,拆分成許多組件。 containerd(容器執行核心)、runc(呼叫 Linux namespace/cgroup 的 runtime)、BuildKit(建構映像) 和 SwarmKit(叢集),讓社群或廠商能自由組合需要的部分。
今天要來介紹一個近年來越來越受到矚目的容器工具 — Podman。 使用過 Docker 的話,你會發現 Podman 的指令幾乎一模一樣,不過 Podman 在設計理念與安全性上有著非常大的不同。
因為 docker 具有 Host 的 root,你可以把特定的目錄 bind-mount 掛進容器裡面,並且在容器中做一些外面不能做的指令。
Podman (short for pod manager) is an open source tool for developing, managing, and running containers. Developed by Red Hat® engineers along with the open source community, Podman manages the entire container ecosystem using the libpod library.
Podman’s daemonless and inclusive architecture makes it an accessible, security-focused option for container management. Its accompanying tools and features, such as Buildah and Skopeo, let developers customize their container environments to suit their needs. Developers can also take advantage of Podman Desktop, a graphical user interface (GUI) for using Podman in local environments.
# CentOS / RHEL
sudo yum -y install podman
# Ubuntu / Debian
sudo apt-get -y install podman
# 裝好之後驗收指令
podman --version
功能 | Docker 指令 | Podman 指令 |
---|---|---|
執行容器 | docker run -it alpine sh |
podman run -it alpine sh |
查看容器 | docker ps |
podman ps |
建立映像 | docker build -t myapp . |
podman build -t myapp . |
登入 Registry | docker login |
podman login |
移除容器 | docker rm <id> |
podman rm <id> |
看起來是換湯不換藥
# 建立一個 pod
podman pod create --name mypod -p 8080:80
# 在 pod 內跑容器
podman run -dt --pod mypod nginx
podman run -dt --pod mypod redis
這樣 nginx 和 redis 就在同一個 Pod 裡,可以共享網路與命名空間。
podman generate systemd --name mycontainer > /etc/systemd/system/mycontainer.service