运行时怎么选(Docker / Podman / Containerd),编排怎么选(Compose / K8s)
| 维度 | Docker | Podman | Containerd |
|---|---|---|---|
| 架构 | C/S 架构,dockerd 守护进程 | 无守护进程,fork/exec 模型 | 嵌入式运行时,无独立 CLI |
| CLI 兼容性 | 原生 docker 命令 | 兼容 docker 命令(alias docker=podman) | ctr/nerdctl(nerdctl 兼容 docker) |
| 守护进程 | 需要 dockerd 运行 | 不需要守护进程 | 作为库嵌入容器平台 |
| Rootless | 支持(需配置) | 原生支持(默认 rootless) | 支持(需配置) |
| 镜像管理 | docker pull / push | podman pull / push | ctr / nerdctl pull |
| Compose 支持 | docker compose(内置) | podman-compose(外部工具) | nerdctl compose |
| Kubernetes 集成 | 需配置(已弃用 dockershim) | podman generate kube | 原生 CRI 接口 |
| 社区生态 | 最成熟,文档最全 | Red Hat 主导,RHEL 默认 | K8s 默认运行时 |
生态最成熟,文档最全,Compose 集成最好。本地开发、CI/CD、学习容器技术的最佳选择。
无需 root 权限运行容器,适合安全要求高的生产环境。RHEL/CentOS 默认容器工具。
作为 K8s 的 CRI 运行时,轻量高效。nerdctl 提供了 docker 兼容的 CLI 体验。
| Docker | Podman | nerdctl |
|---|---|---|
| docker run -d nginx | podman run -d nginx | nerdctl run -d nginx |
| docker ps | podman ps | nerdctl ps |
| docker build -t app . | podman build -t app . | nerdctl build -t app . |
| docker pull nginx:alpine | podman pull nginx:alpine | nerdctl pull nginx:alpine |
| docker compose up -d | podman-compose up -d | nerdctl compose up -d |
| docker images | podman images | nerdctl images |
| docker exec -it app sh | podman exec -it app sh | nerdctl exec -it app sh |
| docker logs app | podman logs app | nerdctl logs app |
这两个不是同层的替代品——Compose 管的是「单台机器上一组容器怎么启动」,K8s 管的是「一批容器在多台机器上始终以什么状态运行」。选型的关键不是哪个更先进,而是你有几台机器、痛点是哪几个。
| 维度 | Docker Compose | Kubernetes |
|---|---|---|
| 作用范围 | 单台机器 | 多节点集群 |
| 配置方式 | 一个 compose.yaml | 一组 YAML(Deployment / Service / ConfigMap …) |
| 自愈 | restart: always,仅限同一台机器 | 控制器跨节点重建,节点失联也能迁走 |
| 滚动发布与回滚 | 需手工编排,存在中断窗口 | Deployment 原生滚动更新,回滚是一条命令 |
| 学习与运维成本 | 低,一个文件搞定 | 高,还需网络 / 存储 / 入口 / 可观测性等配套 |
| 适合 | 单机、少量服务、本地开发、个人项目 | 多机调度、自动扩缩、要求不停机发布的场景 |