Fedora 32
Sponsored Link

Podman : Pod を作成する2020/05/11

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

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

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

953c902fd9430ac86dd38169aa002594399144f19246be1295f7814f39bd72d7

# 確認

[root@dlp ~]#
podman pod ls

POD ID         NAME       STATUS    CREATED          # OF CONTAINERS   INFRA ID
953c902fd943   test_pod   Created   10 seconds ago   1                 69389ebf474f

# pod の詳細を表示

[root@dlp ~]#
podman pod inspect test_pod

{
     "Config": {
          "id": "953c902fd9430ac86dd38169aa002594399144f19246be1295f7814f39bd72d7",
          "name": "test_pod",
          "hostname": "test_pod",
          "labels": {

          },
          "cgroupParent": "machine.slice",
          "sharesCgroup": true,
          "sharesIpc": true,
          "sharesNet": true,
          "sharesUts": true,
          "infraConfig": {
               "makeInfraContainer": true,
               "infraPortBindings": [
                    {
                         "hostPort": 8081,
                         "containerPort": 80,
                         "protocol": "tcp",
                         "hostIP": ""
                    }
               ]
          },
          "created": "2020-05-11T11:28:36.949330512+09:00",
          "lockID": 12
     },
     "State": {
          "cgroupPath": "machine.slice/machine-libpod_pod_953c902fd9430ac86dd38169aa002594399144f19246be1295f7814f39bd72d7.slice",
          "infraContainerID": "69389ebf474f512a887b5e23194fd739e4b0ec3ef761aeae2c9c1715deda5a36",
          "status": "Created"
     },
     "Containers": [
          {
               "id": "69389ebf474f512a887b5e23194fd739e4b0ec3ef761aeae2c9c1715deda5a36",
               "state": "configured"
          }
     ]
}

[root@dlp ~]#
podman images

REPOSITORY                          TAG      IMAGE ID       CREATED          SIZE
srv.world/nginx_server              latest   f0bde03754eb   38 minutes ago   406 MB
dlp.srv.world:5000/nginx_server     latest   f0bde03754eb   38 minutes ago   406 MB
srv.world/fedora_httpd              latest   a461b4b0b704   42 minutes ago   452 MB
registry.fedoraproject.org/fedora   latest   d81c91deec0d   11 days ago      208 MB
k8s.gcr.io/pause                    3.2      80d28bedfe5d   2 months ago     688 kB
docker.io/library/registry          2        708bc6af7e5e   3 months ago     26.3 MB

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

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

9047ef44c13eee5f8f2ab9848a833cb4c8f8cfc6c7dbfe2dc259a850819083ec

[root@dlp ~]#
podman ps -a

CONTAINER ID  IMAGE                                     COMMAND               CREATED             STATUS                       PORTS                   NAMES
9047ef44c13e  srv.world/nginx_server:latest             /usr/sbin/nginx -...  About a minute ago  Up About a minute ago        0.0.0.0:8081->80/tcp    agitated_almeida
.....
.....

# アクセス確認

[root@dlp ~]#
curl localhost:8081

Podman Test on Nginx
# pod を停止する

[root@dlp ~]#
podman pod stop test_pod

953c902fd9430ac86dd38169aa002594399144f19246be1295f7814f39bd72d7

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

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

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

REPOSITORY                          TAG      IMAGE ID       CREATED          SIZE
srv.world/nginx_server              latest   f0bde03754eb   41 minutes ago   406 MB
dlp.srv.world:5000/nginx_server     latest   f0bde03754eb   41 minutes ago   406 MB
srv.world/fedora_httpd              latest   a461b4b0b704   45 minutes ago   452 MB
registry.fedoraproject.org/fedora   latest   d81c91deec0d   11 days ago      208 MB
k8s.gcr.io/pause                    3.2      80d28bedfe5d   2 months ago     688 kB
docker.io/library/registry          2        708bc6af7e5e   3 months ago     26.3 MB

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

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

ae07178a143eb4af271669a08774b055bd96ec878216cf5118b1d63749d0f52d

[root@dlp ~]#
podman pod ls

POD ID         NAME        STATUS    CREATED         # OF CONTAINERS   INFRA ID
fea26c02db58   test_pod2   Running   8 seconds ago   2                 5f291b34376b

[root@dlp ~]#
podman ps -a

CONTAINER ID  IMAGE                                     COMMAND               CREATED         STATUS                       PORTS                   NAMES
ae07178a143e  srv.world/nginx_server:latest             /usr/sbin/nginx -...  21 seconds ago  Up 21 seconds ago            0.0.0.0:80->80/tcp      epic_galileo
.....
.....

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

6e9ddb57194403bed4c3c7a61032a2837c6a82011e6eb16b3b1222a52c4c7a34

[root@dlp ~]#
podman ps -a

CONTAINER ID  IMAGE                                     COMMAND               CREATED         STATUS                       PORTS                   NAMES
6e9ddb571944  docker.io/library/mariadb:latest          mysqld                13 seconds ago  Up 12 seconds ago            0.0.0.0:80->80/tcp      sweet_noyce
ae07178a143e  srv.world/nginx_server:latest             /usr/sbin/nginx -...  2 minutes ago   Up 2 minutes ago             0.0.0.0:80->80/tcp      epic_galileo
5f291b34376b  k8s.gcr.io/pause:3.2                                            2 minutes ago   Up 2 minutes ago             0.0.0.0:80->80/tcp      fea26c02db58-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      | test_pod2 |
+---------------+-----------+
関連コンテンツ