Debian 12 bookworm
Sponsored Link

Podman : Pod を作成する2023/06/21

 
Kubernetes でおなじみの Pod も Podman で作成可能です。
[1] Pod を作成してコンテナーを追加します。
# 空の pod を新規作成
# -p [バインドするポート] -n [pod の名前]

root@dlp:~#
podman pod create -p 8081:80 -n test-pod

20889920c2fc33fd8fc73cafdf98d23d069b4e33654ca247c9a84fbfd90e4ef1

# 確認

root@dlp:~#
podman pod ls

POD ID        NAME        STATUS      CREATED         INFRA ID      # OF CONTAINERS
20889920c2fc  test-pod    Created     14 seconds ago  89a87cf6104a  1

# pod の詳細を表示

root@dlp:~#
podman pod inspect test-pod

{
     "Id": "20889920c2fc33fd8fc73cafdf98d23d069b4e33654ca247c9a84fbfd90e4ef1",
     "Name": "test-pod",
     "Created": "2023-06-20T19:33:28.99473824-05:00",
     "CreateCommand": [
          "podman",
          "pod",
          "create",
          "-p",
          "8081:80",
          "-n",
          "test-pod"
     ],
     "ExitPolicy": "continue",
     "State": "Created",
     "Hostname": "",
     "CreateCgroup": true,
     "CgroupParent": "machine.slice",
     "CgroupPath": "machine.slice/machine-libpod_pod_20889920c2fc33fd8fc73cafdf98d23d069b4e33654ca247c9a84fbfd90e4ef1.slice",
     "CreateInfra": true,
     "InfraContainerID": "89a87cf6104aabe45e703c43b7ca981f854e49eb16cbd1f335af527f3f1b2c9b",
     "InfraConfig": {
          "PortBindings": {
               "80/tcp": [
                    {
                         "HostIp": "",
                         "HostPort": "8081"
                    }
               ]
          },
          "HostNetwork": false,
          "StaticIP": "",
          "StaticMAC": "",
          "NoManageResolvConf": false,
          "DNSServer": null,
          "DNSSearch": null,
          "DNSOption": null,
          "NoManageHosts": false,
          "HostAdd": null,
          "Networks": [
               "podman"
          ],
          "NetworkOptions": null,
          "pid_ns": "private",
          "userns": "host",
          "uts_ns": "private"
     },
     "SharedNamespaces": [
          "ipc",
          "net",
          "uts"
     ],
     "NumContainers": 1,
     "Containers": [
          {
               "Id": "89a87cf6104aabe45e703c43b7ca981f854e49eb16cbd1f335af527f3f1b2c9b",
               "Name": "20889920c2fc-infra",
               "State": "created"
          }
     ]
}

root@dlp:~#
podman images

REPOSITORY                  TAG         IMAGE ID      CREATED             SIZE
localhost/podman-pause      4.3.1-0     27bd47a0cfe1  About a minute ago  776 kB
localhost/root_web          latest      95ff1ec2c79f  7 minutes ago       158 MB
srv.world/iproute           latest      e5a651fe23a6  20 minutes ago      157 MB
srv.world/debian-nginx      latest      e2938e55cf7c  50 minutes ago      158 MB
srv.world/debian-apache2    latest      f047c6f28c56  57 minutes ago      260 MB
docker.io/library/mariadb   latest      99833200524a  4 days ago          410 MB
docker.io/library/registry  2           4bb5ea59f8e0  5 days ago          24.6 MB
docker.io/library/debian    latest      49081a1edb0b  8 days ago          121 MB

# コンテナーを起動して pod に追加する

root@dlp:~#
podman run -dt --pod test-pod srv.world/debian-nginx

3b83a201ea392b46777e7481eed9831ec8e3f261685946aa2ab7f0aab3af402a

root@dlp:~#
podman ps

CONTAINER ID  IMAGE                           COMMAND               CREATED             STATUS             PORTS                 NAMES
89a87cf6104a  localhost/podman-pause:4.3.1-0                        About a minute ago  Up 10 seconds ago  0.0.0.0:8081->80/tcp  20889920c2fc-infra
3b83a201ea39  srv.world/debian-nginx:latest   /usr/sbin/nginx -...  9 seconds ago       Up 10 seconds ago  0.0.0.0:8081->80/tcp  sweet_dijkstra

# アクセス確認

root@dlp:~#
curl localhost:8081

Podman Test on Nginx
# pod を停止する

root@dlp:~#
podman pod stop test-pod

20889920c2fc33fd8fc73cafdf98d23d069b4e33654ca247c9a84fbfd90e4ef1

# pod を削除する (コンテナーも含めて強制削除)

root@dlp:~#
podman pod rm test-pod --force

20889920c2fc33fd8fc73cafdf98d23d069b4e33654ca247c9a84fbfd90e4ef1
[2] Pod の作成とコンテナーの追加を同時に実行することもできます。
root@dlp:~#
podman images

REPOSITORY                  TAG         IMAGE ID      CREATED         SIZE
localhost/podman-pause      4.3.1-0     27bd47a0cfe1  2 minutes ago   776 kB
localhost/root_web          latest      95ff1ec2c79f  8 minutes ago   158 MB
srv.world/iproute           latest      e5a651fe23a6  22 minutes ago  157 MB
srv.world/debian-nginx      latest      e2938e55cf7c  52 minutes ago  158 MB
srv.world/debian-apache2    latest      f047c6f28c56  59 minutes ago  260 MB
docker.io/library/mariadb   latest      99833200524a  4 days ago      410 MB
docker.io/library/registry  2           4bb5ea59f8e0  5 days ago      24.6 MB
docker.io/library/debian    latest      49081a1edb0b  8 days ago      121 MB

# [test-pod2] を新規作成して [srv.world/centos-nginx] コンテナーを追加する

root@dlp:~#
podman run -dt --pod new:test-pod2 -p 80:80 -p 3306:3306 srv.world/debian-nginx

8aef8c0efd44a4401341fac197e8d6bda1be3dfb49fbcaab7a3b2ee19b5a62d5

root@dlp:~#
podman pod ls

POD ID        NAME        STATUS      CREATED         INFRA ID      # OF CONTAINERS
598975654d31  test-pod2   Running     13 seconds ago  f2ed58888a2f  2

root@dlp:~#
podman ps

CONTAINER ID  IMAGE                           COMMAND               CREATED         STATUS             PORTS                                       NAMES
f2ed58888a2f  localhost/podman-pause:4.3.1-0                        31 seconds ago  Up 32 seconds ago  0.0.0.0:80->80/tcp, 0.0.0.0:3306->3306/tcp  598975654d31-infra
8aef8c0efd44  srv.world/debian-nginx:latest   /usr/sbin/nginx -...  31 seconds ago  Up 32 seconds ago  0.0.0.0:80->80/tcp, 0.0.0.0:3306->3306/tcp  sad_blackwell

# [mariadb] コンテナーを起動して [test-pod2] に追加する

root@dlp:~#
podman run -dt --pod test-pod2 -e MYSQL_ROOT_PASSWORD=Password docker.io/library/mariadb

0e6342196221de2a74c7a5f40e754846717d9e6aede58e12cdef7f100db08278

root@dlp:~#
podman ps

CONTAINER ID  IMAGE                             COMMAND               CREATED             STATUS                 PORTS                                       NAMES
f2ed58888a2f  localhost/podman-pause:4.3.1-0                          About a minute ago  Up About a minute ago  0.0.0.0:80->80/tcp, 0.0.0.0:3306->3306/tcp  598975654d31-infra
8aef8c0efd44  srv.world/debian-nginx:latest     /usr/sbin/nginx -...  About a minute ago  Up About a minute ago  0.0.0.0:80->80/tcp, 0.0.0.0:3306->3306/tcp  sad_blackwell
0e6342196221  docker.io/library/mariadb:latest  mariadbd              12 seconds ago      Up 13 seconds ago      0.0.0.0:80->80/tcp, 0.0.0.0:3306->3306/tcp  friendly_yalow

root@dlp:~#
curl dlp.srv.world

Dockerfile Test on Nginx
root@dlp:~#
mysql -u root -p -h dlp.srv.world -e "show variables like 'hostname';"

Enter password:
+---------------+-----------+
| Variable_name | Value     |
+---------------+-----------+
| hostname      | test-pod2 |
+---------------+-----------+
関連コンテンツ