CentOS 8
Sponsored Link

Podman : Pod を作成する2019/10/11

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

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

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

d688dbff0b271ad2fbefbfdc9259509d8877572f95983bb3f2f6b57b253bc074

# 確認

[root@dlp ~]#
podman pod ls

POD ID         NAME       STATUS    CREATED              # OF CONTAINERS   INFRA ID
d688dbff0b27   test_pod   Running   About a minute ago   1                 c2dffc8dbcfa

# pod の詳細を表示

[root@dlp ~]#
podman pod inspect test_pod

{
     "Config": {
          "id": "d688dbff0b271ad2fbefbfdc9259509d8877572f95983bb3f2f6b57b253bc074",
          "name": "test_pod",
          "labels": null,
          "cgroupParent": "machine.slice",
          "sharesCgroup": true,
          "sharesIpc": true,
          "sharesNet": true,
          "sharesUts": true,
          "infraConfig": {
               "makeInfraContainer": true,
               "infraPortBindings": [
                    {
                         "hostPort": 8081,
                         "containerPort": 80,
                         "protocol": "tcp",
                         "hostIP": ""
                    }
               ]
          },
          "created": "2019-10-11T14:38:06.494546769+09:00"
     },
     "State": {
          "cgroupPath": "machine.slice/machine-libpod_pod_d688dbff0b271ad2fbefbfdc9259509d8877572f95983bb3f2f6b57b253bc074.slice",
          "infraContainerID": "c2dffc8dbcfae4662d844ae222b6d2f92e1791ac1f759b1cb51feb2aaae75dfe"
     },
     "Containers": [
          {
               "id": "c2dffc8dbcfae4662d844ae222b6d2f92e1791ac1f759b1cb51feb2aaae75dfe",
               "state": "running"
          }
     ]
}

[root@dlp ~]#
podman images

REPOSITORY                        TAG      IMAGE ID       CREATED         SIZE
srv.world/nginx_server            latest   41c48e1d2421   15 hours ago    308 MB
srv.world/centos_httpd            latest   67edc4066f76   21 hours ago    368 MB
docker.io/library/centos          latest   0f3e07c0138f   9 days ago      227 MB
docker.io/library/registry        2        f32a97de94e1   7 months ago    26.4 MB
quay.io/libpod/alpine_nginx       latest   3ef70f7291f4   11 months ago   9.21 MB
k8s.gcr.io/pause                  3.1      da86e6ba6ca1   21 months ago   747 kB

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

[root@dlp ~]#
podman run -dt --pod test_pod srv.world/nginx_server

924aff9ec480aa2e2b611b4c16e7df85f1ffb8d045dce946fbc53367ea99f264

[root@dlp ~]#
podman ps -a

CONTAINER ID  IMAGE                          COMMAND               CREATED         STATUS             PORTS                 NAMES
924aff9ec480  srv.world/nginx_server:latest  /usr/sbin/nginx -...  4 minutes ago   Up 4 minutes ago                         zen_keller
c2dffc8dbcfa  k8s.gcr.io/pause:3.1                                 11 minutes ago  Up 11 minutes ago  0.0.0.0:8081->80/tcp  d688dbff0b27-infra

# アクセス確認

[root@dlp ~]#
curl localhost:8081

Podman Test on Nginx
# pod を停止する

[root@dlp ~]#
podman pod stop test_pod

d688dbff0b271ad2fbefbfdc9259509d8877572f95983bb3f2f6b57b253bc074

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

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

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

REPOSITORY                        TAG      IMAGE ID       CREATED         SIZE
srv.world/nginx_server            latest   41c48e1d2421   15 hours ago    308 MB
srv.world/centos_httpd            latest   67edc4066f76   22 hours ago    368 MB
docker.io/library/centos          latest   0f3e07c0138f   9 days ago      227 MB
docker.io/library/registry        2        f32a97de94e1   7 months ago    26.4 MB
quay.io/libpod/alpine_nginx       latest   3ef70f7291f4   11 months ago   9.21 MB
k8s.gcr.io/pause                  3.1      da86e6ba6ca1   21 months ago   747 kB

# [test_pod2] pod の新規作成と コンテナーの起動 & pod への追加を同時に行う

[root@dlp ~]#
podman run -dt --pod new:test_pod2 -p 80:80 -p 3306:3306 srv.world/nginx_server

7155112d6c1993949c230719ee1f5239266e95dabda1c6746e60cca30867935d

[root@dlp ~]#
podman pod ls

POD ID         NAME        STATUS    CREATED          # OF CONTAINERS   INFRA ID
a3c2dae83c3f   test_pod2   Running   11 seconds ago   2                 f38a5347001b

[root@dlp ~]#
podman ps -a

CONTAINER ID  IMAGE                          COMMAND               CREATED         STATUS             PORTS                                       NAMES
7155112d6c19  srv.world/nginx_server:latest  /usr/sbin/nginx -...  19 seconds ago  Up 19 seconds ago                                              dazzling_bassi
f38a5347001b  k8s.gcr.io/pause:3.1                                 19 seconds ago  Up 19 seconds ago  0.0.0.0:80->80/tcp, 0.0.0.0:3306->3306/tcp  a3c2dae83c3f-infra

[root@dlp ~]#
podman run -dt --pod test_pod2 -e MYSQL_ROOT_PASSWORD=Password mariadb

62a8fdaefec08e0cfa7a08e1a9ccdcd07cc39ea4ae5279dbe1e0774ac8305488

[root@dlp ~]#
podman ps -a

CONTAINER ID  IMAGE                             COMMAND               CREATED         STATUS             PORTS                                       NAMES
62a8fdaefec0  docker.io/library/mariadb:latest  docker-entrypoint...  12 seconds ago  Up 11 seconds ago                                              keen_franklin
7155112d6c19  srv.world/nginx_server:latest     /usr/sbin/nginx -...  50 seconds ago  Up 50 seconds ago                                              dazzling_bassi
f38a5347001b  k8s.gcr.io/pause:3.1                                    50 seconds ago  Up 50 seconds ago  0.0.0.0:80->80/tcp, 0.0.0.0:3306->3306/tcp  a3c2dae83c3f-infra

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