Fedora 35
Sponsored Link

Podman : Pod を作成する2021/11/11

 
Kubernetes でおなじみの Pod も Podman で作成可能です。
[1] Pod を作成してコンテナーを追加します。
# 空の pod を新規作成

# -p [バインドするポート] -n [pod の名前]

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

19182e5e788c172ca0012a6d9081dee5043dd5c3fb4d5941ecbc69d1cab23a7e

# 確認

[root@dlp ~]#
podman pod ls

POD ID        NAME        STATUS      CREATED         INFRA ID      # OF CONTAINERS
19182e5e788c  test-pod    Created     13 seconds ago  8772d822c8a0  1

# pod の詳細を表示

[root@dlp ~]#
podman pod inspect test-pod

{
     "Id": "19182e5e788c172ca0012a6d9081dee5043dd5c3fb4d5941ecbc69d1cab23a7e",
     "Name": "test-pod",
     "Created": "2021-11-11T10:47:32.871314326+09:00",
     "CreateCommand": [
          "podman",
          "pod",
          "create",
          "-p",
          "8081:80",
          "-n",
          "test-pod"
     ],
     "State": "Created",
     "Hostname": "",
     "CreateCgroup": true,
     "CgroupParent": "machine.slice",
     "CgroupPath": "machine.slice/machine-libpod_pod_19182e5e788c172ca0012a6d9081dee5043dd5c3fb4d5941ecbc69d1cab23a7e.slice",
     "CreateInfra": true,
     "InfraContainerID": "8772d822c8a03a01d2182141b97d6a05ba3cde8dfde5039d398cf35a58354685",
     "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": [
          "uts",
          "ipc",
          "net"
     ],
     "NumContainers": 1,
     "Containers": [
          {
               "Id": "8772d822c8a03a01d2182141b97d6a05ba3cde8dfde5039d398cf35a58354685",
               "Name": "19182e5e788c-infra",
               "State": "configured"
          }
     ]
}

[root@dlp ~]#
podman images

REPOSITORY                         TAG         IMAGE ID      CREATED            SIZE
localhost/root_web                 latest      0a40f10d61ec  46 minutes ago     391 MB
srv.world/fedora-nginx             latest      f27df6dc0cf8  About an hour ago  391 MB
srv.world/fedora-httpd             latest      3b282c5eda58  2 hours ago        418 MB
docker.io/library/mariadb          latest      e2278f24ac88  24 hours ago       416 MB
registry.fedoraproject.org/fedora  latest      1b52edb08181  7 days ago         159 MB
k8s.gcr.io/pause                   3.5         ed210e3e4a5b  7 months ago       690 kB

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

[root@dlp ~]#
podman run -dt --pod test-pod srv.world/fedora-nginx

e6485dae58730b79f05ce23f5a2d33f3473c5b2d04855db9ea06a7fafd6dcf0d

[root@dlp ~]#
podman ps

CONTAINER ID  IMAGE                          COMMAND               CREATED             STATUS            PORTS                 NAMES
8772d822c8a0  k8s.gcr.io/pause:3.5                                 About a minute ago  Up 9 seconds ago  0.0.0.0:8081->80/tcp  19182e5e788c-infra
e6485dae5873  srv.world/fedora-nginx:latest  /usr/sbin/nginx -...  8 seconds ago       Up 9 seconds ago  0.0.0.0:8081->80/tcp  wizardly_bassi

# アクセス確認

[root@dlp ~]#
curl localhost:8081

Podman Test on Nginx
# pod を停止する

[root@dlp ~]#
podman pod stop test-pod

19182e5e788c172ca0012a6d9081dee5043dd5c3fb4d5941ecbc69d1cab23a7e

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

[root@dlp ~]#
podman pod rm test-pod --force

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

REPOSITORY                         TAG         IMAGE ID      CREATED            SIZE
localhost/root_web                 latest      0a40f10d61ec  48 minutes ago     391 MB
srv.world/fedora-nginx             latest      f27df6dc0cf8  About an hour ago  391 MB
srv.world/fedora-httpd             latest      3b282c5eda58  2 hours ago        418 MB
docker.io/library/mariadb          latest      e2278f24ac88  24 hours ago       416 MB
registry.fedoraproject.org/fedora  latest      1b52edb08181  7 days ago         159 MB
k8s.gcr.io/pause                   3.5         ed210e3e4a5b  7 months ago       690 kB

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

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

7b09ffafa1c72edea7612f5d28f7700a580034adc2d6e6bfe01aa9e37e24ed21

[root@dlp ~]#
podman pod ls

POD ID        NAME        STATUS      CREATED        INFRA ID      # OF CONTAINERS
1f849e01c353  test-pod2   Running     8 seconds ago  608f03d0aab2  2

[root@dlp ~]#
podman ps

CONTAINER ID  IMAGE                          COMMAND               CREATED         STATUS             PORTS                                       NAMES
608f03d0aab2  k8s.gcr.io/pause:3.5                                 20 seconds ago  Up 20 seconds ago  0.0.0.0:80->80/tcp, 0.0.0.0:3306->3306/tcp  1f849e01c353-infra
7b09ffafa1c7  srv.world/fedora-nginx:latest  /usr/sbin/nginx -...  20 seconds ago  Up 20 seconds ago  0.0.0.0:80->80/tcp, 0.0.0.0:3306->3306/tcp  quizzical_knuth

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

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

5755b15b298a0bd95afee5972565ebab7624bebd5e736e183f0ded7b6c13f697

[root@dlp ~]#
podman ps

CONTAINER ID  IMAGE                             COMMAND               CREATED             STATUS                 PORTS                                       NAMES
608f03d0aab2  k8s.gcr.io/pause:3.5                                    About a minute ago  Up About a minute ago  0.0.0.0:80->80/tcp, 0.0.0.0:3306->3306/tcp  1f849e01c353-infra
7b09ffafa1c7  srv.world/fedora-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  quizzical_knuth
5755b15b298a  docker.io/library/mariadb:latest  mariadbd              8 seconds ago       Up 8 seconds ago       0.0.0.0:80->80/tcp, 0.0.0.0:3306->3306/tcp  funny_goldstine

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