Fedora 36
Sponsored Link

Podman : Create Pods
2022/05/24
 
Create Pods like Kubernetes.
[1] Create a Pod and add a Container to it.
# create a empty pod
# -p [bind port] -n [pod name]

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

aeafd08a2e247da28aeead033ff82a3135335b4689656969e9287c0323f5bf48

# show pods

[root@dlp ~]#
podman pod ls

POD ID        NAME        STATUS      CREATED         INFRA ID      # OF CONTAINERS
aeafd08a2e24  test-pod    Created     11 seconds ago  5d1d0496966d  1

# show details of pod

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

{
     "Id": "aeafd08a2e247da28aeead033ff82a3135335b4689656969e9287c0323f5bf48",
     "Name": "test-pod",
     "Created": "2022-05-24T11:12:22.481077461+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_aeafd08a2e247da28aeead033ff82a3135335b4689656969e9287c0323f5bf48.slice",
     "CreateInfra": true,
     "InfraContainerID": "5d1d0496966dc287ab7bf7c01b8e540c54c03ce8b891ae397b1a97e9571e81db",
     "InfraConfig": {
          "PortBindings": {
               "80/tcp": [
     {
          "HostIp": "",
          "HostPort": "8081"
     }
]
          },
          "HostNetwork": false,
          "StaticIP": "",
          "StaticMAC": "",
          "NoManageResolvConf": false,
          "DNSServer": null,
          "DNSSearch": null,
          "DNSOption": null,
          "NoManageHosts": false,
          "HostAdd": null,
          "Networks": [
               "podman"
          ],
          "NetworkOptions": null,
          "pid_ns": "private",
          "userns": "host"
     },
     "SharedNamespaces": [
          "ipc",
          "net",
          "uts"
     ],
     "NumContainers": 1,
     "Containers": [
          {
               "Id": "5d1d0496966dc287ab7bf7c01b8e540c54c03ce8b891ae397b1a97e9571e81db",
               "Name": "aeafd08a2e24-infra",
               "State": "created"
          }
     ]
}

[root@dlp ~]#
podman images

REPOSITORY                         TAG               IMAGE ID      CREATED            SIZE
localhost/podman-pause             4.1.0-1651853754  64648fcd477f  56 seconds ago     816 kB
docker.io/library/root_web         latest            e1783cd9a348  21 minutes ago     467 MB
localhost/root_web                 latest            709b93cf49d3  22 minutes ago     467 MB
srv.world/fedora-nginx             latest            bfad5d240798  58 minutes ago     467 MB
srv.world/fedora-httpd             latest            6c88b642f75c  About an hour ago  566 MB
docker.io/library/mariadb          latest            784190069700  8 hours ago        396 MB
registry.fedoraproject.org/fedora  latest            750037c05cfe  3 months ago       159 MB
dlp.srv.world:5000/fedora          my-registry       750037c05cfe  3 months ago       159 MB

# run container and add it to pod

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

a358f001c56115855ede00ac39122e7e2224cd48e5c0eaf8f658a6e4e56399ec

[root@dlp ~]#
podman ps

CONTAINER ID  IMAGE                                    COMMAND               CREATED             STATUS            PORTS                 NAMES
5d1d0496966d  localhost/podman-pause:4.1.0-1651853754                        About a minute ago  Up 9 seconds ago  0.0.0.0:8081->80/tcp  aeafd08a2e24-infra
a358f001c561  srv.world/fedora-nginx:latest            /usr/sbin/nginx -...  9 seconds ago       Up 9 seconds ago  0.0.0.0:8081->80/tcp  elated_heisenberg

# verify accesses

[root@dlp ~]#
curl localhost:8081

Podman Test on Nginx
# stop pod

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

aeafd08a2e247da28aeead033ff82a3135335b4689656969e9287c0323f5bf48

# remove pod (removed containers all)

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

aeafd08a2e247da28aeead033ff82a3135335b4689656969e9287c0323f5bf48
[2] It's possbile to create Pod and add Container with one command.
[root@dlp ~]#
podman images

REPOSITORY                         TAG               IMAGE ID      CREATED            SIZE
localhost/podman-pause             4.1.0-1651853754  64648fcd477f  8 minutes ago      816 kB
docker.io/library/root_web         latest            e1783cd9a348  28 minutes ago     467 MB
localhost/root_web                 latest            709b93cf49d3  29 minutes ago     467 MB
srv.world/fedora-nginx             latest            bfad5d240798  About an hour ago  467 MB
srv.world/fedora-httpd             latest            6c88b642f75c  About an hour ago  566 MB
docker.io/library/mariadb          latest            784190069700  8 hours ago        396 MB
registry.fedoraproject.org/fedora  latest            750037c05cfe  3 months ago       159 MB
dlp.srv.world:5000/fedora          my-registry       750037c05cfe  3 months ago       159 MB

# create a [test-pod2] pod and add [srv.world/fedora-nginx] container

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

d6e66de03d4bbfb32d10122387811f5291b76348a33784b1c075c387337d1f99

[root@dlp ~]#
podman pod ls

POD ID        NAME        STATUS      CREATED        INFRA ID      # OF CONTAINERS
ede58247cd3e  test-pod2   Running     7 seconds ago  3d27f302b524  2

[root@dlp ~]#
podman ps

CONTAINER ID  IMAGE                                    COMMAND               CREATED         STATUS             PORTS                                       NAMES
3d27f302b524  localhost/podman-pause:4.1.0-1651853754                        29 seconds ago  Up 29 seconds ago  0.0.0.0:80->80/tcp, 0.0.0.0:3306->3306/tcp  ede58247cd3e-infra
d6e66de03d4b  srv.world/fedora-nginx:latest            /usr/sbin/nginx -...  29 seconds ago  Up 28 seconds ago  0.0.0.0:80->80/tcp, 0.0.0.0:3306->3306/tcp  condescending_fermi

# run [mariadb] container and add it to the [test-pod2]

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

736c31f3f0aace972fbd7806ea87177b3c13aad00118503d7e2aa8fbf722b17e

[root@dlp ~]#
podman ps

CONTAINER ID  IMAGE                                    COMMAND               CREATED             STATUS                 PORTS                                       NAMES
3d27f302b524  localhost/podman-pause:4.1.0-1651853754                        About a minute ago  Up About a minute ago  0.0.0.0:80->80/tcp, 0.0.0.0:3306->3306/tcp  ede58247cd3e-infra
d6e66de03d4b  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  condescending_fermi
736c31f3f0aa  docker.io/library/mariadb:latest         mariadbd              12 seconds ago      Up 13 seconds ago      0.0.0.0:80->80/tcp, 0.0.0.0:3306->3306/tcp  zen_cerf

[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 |
+---------------+-----------+
Matched Content