Ubuntu 22.04
Sponsored Link

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

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

f20604e462ca2e68343776fa3150a8df08469aa3005b062adfdf5980da2e0421

# 確認

root@dlp:~#
podman pod ls

POD ID        NAME        STATUS      CREATED        INFRA ID      # OF CONTAINERS
f20604e462ca  test-pod    Created     8 seconds ago  a4a38b154286  1

# pod の詳細を表示

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

{
     "Id": "f20604e462ca2e68343776fa3150a8df08469aa3005b062adfdf5980da2e0421",
     "Name": "test-pod",
     "Created": "2022-04-28T07:02:13.638313303Z",
     "CreateCommand": [
          "podman",
          "pod",
          "create",
          "-p",
          "8081:80",
          "-n",
          "test-pod"
     ],
     "State": "Created",
     "Hostname": "",
     "CreateCgroup": true,
     "CgroupParent": "machine.slice",
     "CgroupPath": "machine.slice/machine-libpod_pod_f20604e462ca2e68343776fa3150a8df08469aa3005b062adfdf5980da2e0421.slice",
     "CreateInfra": true,
     "InfraContainerID": "a4a38b15428675bf5a917fe3bb8a8135c6d1901c0395767224afd4be1e1387ff",
     "InfraConfig": {
          "PortBindings": {
               "80/tcp": [
     {
          "HostIp": "",
          "HostPort": "8081"
     }
]
          },
          "HostNetwork": true,
          "StaticIP": "",
          "StaticMAC": "",
          "NoManageResolvConf": false,
          "DNSServer": null,
          "DNSSearch": null,
          "DNSOption": null,
          "NoManageHosts": false,
          "HostAdd": null,
          "Networks": null,
          "NetworkOptions": null,
          "pid_ns": "private",
          "userns": "host"
     },
     "SharedNamespaces": [
          "ipc",
          "net",
          "uts"
     ],
     "NumContainers": 1,
     "Containers": [
          {
               "Id": "a4a38b15428675bf5a917fe3bb8a8135c6d1901c0395767224afd4be1e1387ff",
               "Name": "f20604e462ca-infra",
               "State": "configured"
          }
     ]
}

root@dlp:~#
podman images

REPOSITORY                  TAG         IMAGE ID      CREATED            SIZE
srv.world/ubuntu-nginx      latest      00787fa1628b  About an hour ago  170 MB
srv.world/ubuntu-apache2    latest      c5d3a78bc38f  About an hour ago  224 MB
docker.io/library/mariadb   latest      7a1ace59b072  6 days ago         421 MB
docker.io/library/ubuntu    latest      3f4714ee068a  6 days ago         80.3 MB
docker.io/library/registry  2           2e200967d166  3 weeks ago        24.7 MB
k8s.gcr.io/pause            3.5         ed210e3e4a5b  13 months ago      690 kB

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

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

eec3cc1b6e88857703d1f61542041d22a9317d6556e9c5a68caef02387531e8a

root@dlp:~#
podman ps

CONTAINER ID  IMAGE                          COMMAND               CREATED             STATUS            PORTS                 NAMES
a4a38b154286  k8s.gcr.io/pause:3.5                                 About a minute ago  Up 8 seconds ago  0.0.0.0:8081->80/tcp  f20604e462ca-infra
eec3cc1b6e88  srv.world/ubuntu-nginx:latest  /usr/sbin/nginx -...  8 seconds ago       Up 8 seconds ago  0.0.0.0:8081->80/tcp  exciting_bouman

# アクセス確認

root@dlp:~#
curl localhost:8081

Podman Test on Nginx
# pod を停止する

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

f20604e462ca2e68343776fa3150a8df08469aa3005b062adfdf5980da2e0421

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

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

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

REPOSITORY                  TAG     IMAGE ID      CREATED        SIZE
srv.world/ubuntu-nginx      latest  37125087a75f  5 hours ago    216 MB
srv.world/ubuntu-apache2    latest  68a7269c5457  5 hours ago    260 MB
docker.io/library/ubuntu    latest  fe3c5de03486  10 days ago    129 MB
docker.io/library/registry  2       1fd8e1b0bb7e  4 months ago   26.8 MB
k8s.gcr.io/pause            3.2     80d28bedfe5d  18 months ago  688 kB

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

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

63366e847dbff84e7c67961900624272f8762319876c44783144b86478c79063

root@dlp:~#
podman pod ls

POD ID        NAME        STATUS      CREATED         INFRA ID      # OF CONTAINERS
796f464a433c  test-pod2   Running     13 seconds ago  7c1c826b9808  2

root@dlp:~#
podman ps

CONTAINER ID  IMAGE                          COMMAND               CREATED         STATUS             PORTS                                       NAMES
7c1c826b9808  k8s.gcr.io/pause:3.5                                 26 seconds ago  Up 26 seconds ago  0.0.0.0:80->80/tcp, 0.0.0.0:3306->3306/tcp  796f464a433c-infra
63366e847dbf  srv.world/ubuntu-nginx:latest  /usr/sbin/nginx -...  26 seconds ago  Up 26 seconds ago  0.0.0.0:80->80/tcp, 0.0.0.0:3306->3306/tcp  nice_chaum

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

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

63c04b93b764120a7960c04244709bd601f192703206c3d6b49a7740bc38275f

root@dlp:~#
podman ps

CONTAINER ID  IMAGE                             COMMAND               CREATED         STATUS             PORTS                                       NAMES
7c1c826b9808  k8s.gcr.io/pause:3.5                                    59 seconds ago  Up 59 seconds ago  0.0.0.0:80->80/tcp, 0.0.0.0:3306->3306/tcp  796f464a433c-infra
63366e847dbf  srv.world/ubuntu-nginx:latest     /usr/sbin/nginx -...  59 seconds ago  Up 59 seconds ago  0.0.0.0:80->80/tcp, 0.0.0.0:3306->3306/tcp  nice_chaum
63c04b93b764  docker.io/library/mariadb:latest  mariadbd              6 seconds ago   Up 6 seconds ago   0.0.0.0:80->80/tcp, 0.0.0.0:3306->3306/tcp  focused_easley

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 |
+---------------+-----------+
関連コンテンツ