Ubuntu 24.04
Sponsored Link

Podman : Pod を作成する2024/05/05

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

root@dlp:~#
podman pod create -p 8081:80 -n test-pod --security-opt apparmor=unconfined

6a38b319fc87e9d91f956e8a42b82383109fd3686e32e5d200693c5fea89d916

# 確認

root@dlp:~#
podman pod ls

POD ID        NAME        STATUS      CREATED         INFRA ID      # OF CONTAINERS
6a38b319fc87  test-pod    Created     27 seconds ago  9dcc8de8f8b4  1

# pod の詳細を表示

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

{
     "Id": "6a38b319fc87e9d91f956e8a42b82383109fd3686e32e5d200693c5fea89d916",
     "Name": "test-pod",
     "Created": "2024-05-05T05:58:05.874403823Z",
     "CreateCommand": [
          "podman",
          "pod",
          "create",
          "-p",
          "8081:80",
          "-n",
          "test-pod",
          "--security-opt",
          "apparmor=unconfined"
     ],
     "ExitPolicy": "continue",
     "State": "Created",
     "Hostname": "",
     "CreateCgroup": true,
     "CgroupParent": "machine.slice",
     "CgroupPath": "machine.slice/machine-libpod_pod_6a38b319fc87e9d91f956e8a42b82383109fd3686e32e5d200693c5fea89d916.slice",
     "CreateInfra": true,
     "InfraContainerID": "9dcc8de8f8b4810d317afcf13e65b65b23be68dbf06c08228b95db7b2c3411bc",
     "InfraConfig": {
          "PortBindings": {
               "80/tcp": [
                    {
                         "HostIp": "",
                         "HostPort": "8081"
.....
.....

root@dlp:~#
podman images

REPOSITORY                 TAG              IMAGE ID      CREATED         SIZE
localhost/podman-pause     4.9.3-0          070ddb5147bc  26 minutes ago  835 kB
srv.world/iproute          latest           4ef0738fb3ef  2 hours ago     123 MB
srv.world/ubuntu-nginx     latest           1b1a4d3f4f26  4 hours ago     125 MB
srv.world/ubuntu-apache2   latest           38d508336863  4 hours ago     226 MB
dlp.srv.world:5000/ubuntu  my-registry      bf3dc08bfed0  5 days ago      78.7 MB
docker.io/library/ubuntu   latest           bf3dc08bfed0  5 days ago      78.7 MB
docker.io/moby/buildkit    buildx-stable-1  1a21071780b0  9 days ago      199 MB
docker.io/library/mariadb  latest           465bc4da7f09  2 months ago    411 MB

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

root@dlp:~#
podman run -dt --pod test-pod --security-opt apparmor=unconfined srv.world/ubuntu-nginx

f7f309ff404b4c5d298a4ef2ed1344c35a683b3e8983b827d9b2f0102b79614c

root@dlp:~#
podman ps

CONTAINER ID  IMAGE                           COMMAND               CREATED         STATUS         PORTS                 NAMES
9dcc8de8f8b4  localhost/podman-pause:4.9.3-0                        2 minutes ago   Up 30 seconds  0.0.0.0:8081->80/tcp  6a38b319fc87-infra
f7f309ff404b  srv.world/ubuntu-nginx:latest   /usr/sbin/nginx -...  29 seconds ago  Up 30 seconds  0.0.0.0:8081->80/tcp  optimistic_leakey

# アクセス確認

root@dlp:~#
curl localhost:8081

Podman Test on Nginx
# pod を停止する

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

6a38b319fc87e9d91f956e8a42b82383109fd3686e32e5d200693c5fea89d916

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

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

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

REPOSITORY                 TAG              IMAGE ID      CREATED         SIZE
localhost/podman-pause     4.9.3-0          070ddb5147bc  28 minutes ago  835 kB
srv.world/iproute          latest           4ef0738fb3ef  2 hours ago     123 MB
srv.world/ubuntu-nginx     latest           1b1a4d3f4f26  4 hours ago     125 MB
srv.world/ubuntu-apache2   latest           38d508336863  4 hours ago     226 MB
dlp.srv.world:5000/ubuntu  my-registry      bf3dc08bfed0  5 days ago      78.7 MB
docker.io/library/ubuntu   latest           bf3dc08bfed0  5 days ago      78.7 MB
docker.io/moby/buildkit    buildx-stable-1  1a21071780b0  9 days ago      199 MB
docker.io/library/mariadb  latest           465bc4da7f09  2 months ago    411 MB

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

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

06389cc5b98779f3d32b932cd6b980b13344a381ffd45530d90556ad4f70660f

root@dlp:~#
podman pod ls

POD ID        NAME        STATUS      CREATED         INFRA ID      # OF CONTAINERS
ffc470c3105b  test-pod2   Running     16 seconds ago  88b36d876b70  2

root@dlp:~#
podman ps

CONTAINER ID  IMAGE                           COMMAND               CREATED         STATUS         PORTS                                       NAMES
88b36d876b70  localhost/podman-pause:4.9.3-0                        37 seconds ago  Up 37 seconds  0.0.0.0:80->80/tcp, 0.0.0.0:3306->3306/tcp  ffc470c3105b-infra
06389cc5b987  srv.world/ubuntu-nginx:latest   /usr/sbin/nginx -...  37 seconds ago  Up 37 seconds  0.0.0.0:80->80/tcp, 0.0.0.0:3306->3306/tcp  pensive_haslett

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

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

1fdc532a853ecfb960c33472280b640eca15dd949c655721959bba34755312dd

root@dlp:~#
podman ps

CONTAINER ID  IMAGE                             COMMAND               CREATED         STATUS         PORTS                                       NAMES
88b36d876b70  localhost/podman-pause:4.9.3-0                          2 minutes ago   Up 2 minutes   0.0.0.0:80->80/tcp, 0.0.0.0:3306->3306/tcp  ffc470c3105b-infra
06389cc5b987  srv.world/ubuntu-nginx:latest     /usr/sbin/nginx -...  2 minutes ago   Up 2 minutes   0.0.0.0:80->80/tcp, 0.0.0.0:3306->3306/tcp  pensive_haslett
1fdc532a853e  docker.io/library/mariadb:latest  mariadbd              12 seconds ago  Up 13 seconds  0.0.0.0:80->80/tcp, 0.0.0.0:3306->3306/tcp  frosty_nobel

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