Upgrade to Pro — share decks privately, control downloads, hide ads and more …

20210127 Docker 與 Podman 同與不同

Phil Huang
March 02, 2021

20210127 Docker 與 Podman 同與不同

Phil Huang

March 02, 2021
Tweet

More Decks by Phil Huang

Other Decks in Technology

Transcript

  1. # whois Phil Huang 黃秉鈞 • 台灣開源社群積極參與者 ◦ Cloud Native

    Taiwan User Group (CNTUG) ◦ SDNDS-TW • 任職於 Red Hat Solution Architect ◦ Ansible IT Automation ◦ OpenShift Container Platform ◦ Software-Defined Networking (SDN) ◦ Network Function Virtualization (NFV) • Blog ◦ https://blog.pichuang.com.tw Ref: https://www.linkedin.com/in/phil-huang-09b09895/
  2. Agenda • Docker 的現況及當今趨勢 • Podman 介紹 • Docker v.s.

    Podman 比較 • 常見 Podman 使用案例分享
  3. Please READ it first • Docker Registry => Container Registry

    • Docker Images => Container Images • Docker Container => OCI Container • Dockerfile => Containerfile (NEW!) Ref: https://dwalsh.fedorapeople.org/ReplacingDockerWithPodman.pdf OCI: Open Container Initiative
  4. Container? VM? Kubernetes? Ref:https://blog.pichuang.com.tw/20210111-Kubernetes-for-sales-and-marketing/ • VM 就像是提供一個大倉庫,裡面可以隨便塞 東西進去 • Container

    就像是一個一個行李箱,每一個行 李箱都符合 OCI 標準規範建立 • Kubernetes 就像是一個中大型社區的建築藍 圖 (Blueprint) ◦ VM:一棟棟的大樓 ◦ Pod:大樓裡面的住戶 ◦ Container:住戶房間裡面的行李箱
  5. Containers are Linux Ref: Linux Performance http://www.brendangregg.com/linuxperf.html nicolaka/ netshoot -

    https://github.com/nicolaka/netshoot • 技術上來說,一個基本 Linux Container 就是一 個 Linux Process,實踐來自於 Linux Kernel, 而所具備的資安能力也是一樣 • Linux Namespaces • cgroups v1/v2 • SELinux / Apparmor • SECCOMP • 大多數的常見系統工具都還是可以沿用 • Linux Performance Tools • Linux System Tools => 無論是 Docker 或者是 Podman 皆符合條件
  6. Podman: 三隻小海豹在大海 • 全名為 Pod Manager,Podman Pod 的概念跟 Kubernetes Pod

    一樣 • 一個 Pod 可以包含 1 個或 1 個以上的容器 (Container) • Daemonless:直接對符合 OCI Container Runtime 的 runc 操作 • Rootless:不需使用 root 特權帳號即可執行,對系統保護更加安全 • 採取 fork/exec 模式執行:與 Docker 設計不同,更符合 Linux process 原生設計 • 可以輕易跟 Systemd 進行整合使用 Ref: https://podman.io/
  7. 與其他常見容器運行時差異 Ref: https://podman.io/ Ref: Podman and Buildah for Docker users

    https://developers.redhat.com/blog/2019/02/21/podman-and-buildah-for-docker-users/ Client / Server 模型 Fork/Exec 模型
  8. 兩者基本能力是一模一樣的 • 包含常見管理 / 運行 / 建構映像檔 (Container Image) •

    yum install –y podman-docker • podman run / start / build / … • 比較特別的是,如果想要查詢外部容器倉庫的資訊 (External Container Registry),譬如像 tag 或 schema 資訊,會需要用 Skopeo 查詢 => 換個方向問,哪些是 Docker 有,但 Podman 沒有的能力? Ref: Red Hat Developer - Podman Basics Cheat Sheet https://developers.redhat.com/cheat-sheets/podman-basics https://github.com/containers/podman/blob/master/transfer.md#missing-commands-in-podman
  9. 使用 Systemd 啟動 Podman • 相當推薦的系統管理用法 • 內建提供快速建立 Systemd Service

    Unit 指令,可以自行修改成想要的能力 • 若是 non-root user 則可搭配 Systemd User Service 一起使用 $ podman create -p 8080:80 --name web nginx 6d279a1262f59a0cc831c21cd25ad2d1bf61b95f2a7bdd519eef7578502c5e43 $ podman generate systemd --name web -f /home/pichuang/container-web.service $ mkdir -p ~/.config/systemd/user/ $ cp container-web.service ~/.config/systemd/user/container-web.service $ systemctl --user daemon-reload $ systemctl --user enable --now container-web.service $ systemctl --user status container-web.service Ref: Running containers with Podman and shareable systemd services https://www.redhat.com/sysadmin/podman-shareable-systemd-services
  10. 使用 Cockpit 啟動 Podman • 單機即可使用 • 簡易 Podman Web

    UI 管理介面 Ref: Running containers with Podman and shareable systemd services https://www.redhat.com/sysadmin/podman-shareable-systemd-services
  11. Podman 與 Ansible 結合使用 Ref: https://docs.ansible.com/ansible/latest/collections/containers/podman/index.html - name: Using Podman

    collection hosts: localhost tasks: - name: Run redis container containers.podman.podman_container: name: myredis image: redis command: redis-server --appendonly yes state: present recreate: yes expose: - 6379 volumes_from: - mydata • Ansible 支援 containers.podman.* 模組
  12. 使用 Podman 輸出 Kube YAML • 既然可以輸出 Kubernetes YAML,當然也可以運行 Kubernetes

    YAML !!! • 連 replica 設定多少都會完全遵照執行 19 $ podman play kube --help Play a pod based on Kubernetes YAML. Description: Command reads in a structured file of Kubernetes YAML. It creates the pod and containers described in the YAML. The containers within the pod are then started and the ID of the new Pod is output. $ wget https://raw.githubusercontent.com/kubernetes/website/master/content/en/examples/controllers/nginx-deployment.yam l $ cat nginx-deployment.yaml | grep replicas replicas: 3 $ podman play kube ./nginx-deployment.yaml $ podman pod ps POD ID NAME STATUS CREATED # OF CONTAINERS INFRA ID 3856aa3a53fe nginx-deployment-pod-2 Running 26 seconds ago 2 aaff9084887c f03937100d9d nginx-deployment-pod-1 Running 26 seconds ago 2 db40e2417335 254f7faf3320 nginx-deployment-pod-0 Running 47 seconds ago 2 96a6d8c8593b Ref: The podman play kube command now supports deployments https://www.redhat.com/sysadmin/podman-play-kube
  13. 使用 Podman 運行 Kube YAML • 可以在尚未部署到 Kubernetes 測試之前,以運行單一個 Pod

    測試,儘早回饋修正 • 與 Kubernetes 相同,在 Pod 裡面也會有 Pause 容器,存在理由也是為了解決相同問 題,主要共享 Linux Namespace 資源 • 建立 Pod 之後,可以再新增想要放置的容器進去 $ podman run -dt --pod new:nginx-pod --publish=8080:80 docker.io/library/nginx:1.19.3 686db821c649832d6b6c7074fae13831477badf8dec8707000a41d5b11297111 $ podman ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 686db821c649 docker.io/library/nginx:1.19.3 nginx -g daemon o... About a minute ago Up About a minute ago 0.0.0.0:8080->80/tcp heuristic_blackburn e2306e151fed k8s.gcr.io/pause:3.2 About a minute ago Up About a minute ago 0.0.0.0:8080->80/tcp d0606265918b-infra Ref: Podman: Managing pods and containers in a local container runtime https://developers.redhat.com/blog/2019/01/15/podman-managing-containers-pods
  14. Q&A