Ubuntu 24.04
Sponsored Link

Podman : Create Pods2024/05/05

 
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 --security-opt apparmor=unconfined

6a38b319fc87e9d91f956e8a42b82383109fd3686e32e5d200693c5fea89d916

# show pods

root@dlp:~#
podman pod ls

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

# show details of 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

# run container and add it to 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

# verify accesses

root@dlp:~#
curl localhost:8081

Podman Test on Nginx
# stop pod

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

6a38b319fc87e9d91f956e8a42b82383109fd3686e32e5d200693c5fea89d916

# remove pod (removed containers all)

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

6a38b319fc87e9d91f956e8a42b82383109fd3686e32e5d200693c5fea89d916
[2] It's possible to create Pod and add Container with one command.
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

# create a [test_pod2] pod and add [srv.world/ubuntu-nginx] container

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

# run [mariadb] container and add it to the [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 |
+---------------+-----------+
Matched Content