- Level: Beginner
- Estimated time: 30 minutes
- Contents (This content corresponds to Chapter 2)
- Working with containers
- Working with container images
- Building images
$ podman version
Client: Podman Engine
Version: 4.4.1
API Version: 4.4.1
Go Version: go1.19.6
Built: Wed Apr 26 16:50:28 2023
OS/Arch: linux/amd64
Switch to general user (username:rhel
)
# su - rhel
$
(This content corresponds to Chapter 2.1.1)
Execute the podman run
command, pull and execute the ubi8/httpd-24
image
$ podman run -ti --rm registry.access.redhat.com/ubi8/httpd-24 bash
Output result
$ podman run -ti --rm registry.access.redhat.com/ubi8/httpd-24 bash
Trying to pull registry.access.redhat.com/ubi8/httpd-24:latest...
Getting image source signatures
Checking if image destination supports signatures
Copying blob 9ece777c9660 done
Copying blob 70de3d8fc2c6 done
Copying blob b653248f5bcb done
Copying config c4127096ce done
Writing manifest to image destination
Storing signatures
bash-4.4$
Checking OS information in a container
bash-4.4$ grep PRETTY_NAME /etc/os-release
Output result
bash-4.4$ grep PRETTY_NAME /etc/os-release
PRETTY_NAME="Red Hat Enterprise Linux 8.8 (Ootpa)"
Count commands in /usr/bin in container
bash-4.4$ ls /usr/bin/ | wc -l
Output result
bash-4.4$ ls /usr/bin/ | wc -l
526
Try running it on the OS
$ grep PRETTY_NAME /etc/os-release
PRETTY_NAME="Red Hat Enterprise Linux 9.2 (Plow)"
$ ls /usr/bin/ | wc -l
Output result
$ grep PRETTY_NAME /etc/os-release
PRETTY_NAME="Red Hat Enterprise Linux 9.2 (Plow)"
$ ls /usr/bin/ | wc -l
1022
(This content corresponds to Chapter 2.1.2)
Start container in detached mode, port 8080, name myapp
$ podman run -d -p 8080:8080 --name myapp registry.access.redhat.com/ubi8/httpd-24
Output result
$ podman run -d -p 8080:8080 --name myapp registry.access.redhat.com/ubi8/httpd-24
e5558cfdda7d1c2c49c4d5ae59bbfcece64cb219b848ba78ae6cbba787ee8d07
Check myapp port usage.
$ podman port myapp
Output result
$ podman port myapp
8080/tcp -> 0.0.0.0:8080
Start container in detached mode, port 8081, name myapp1
$ podman run -d -p 8081:8080 --name myapp1 registry.access.redhat.com/ubi8/httpd-24
Output result
$ podman run -d -p 8081:8080 --name myapp1 registry.access.redhat.com/ubi8/httpd-24
f6218c8fd423b6ed913fee1d8d612972e3fc4d0cf737a44e058f0fff0f68aeeb
(Optional) Check all container ports.
$ podman port --all
Output result
$ podman port --all
e5558cfdda7d 8080/tcp -> 0.0.0.0:8080
f6218c8fd423 8080/tcp -> 0.0.0.0:8081
(This content corresponds to Chapter:2.1.3)
Stopping the myapp container
$ podman stop myapp
Output result
$ podman stop myapp
myapp
Stop myapp1 container
$ podman stop -t 0 myapp1
Output result
$ podman stop -t 0 myapp1
myapp1
(This content corresponds to Chapter:2.1.4)
Start the myapp container
$ podman start myapp
Output result
$ podman start myapp
myapp
(This content corresponds to Chapter 2.1.5)
Check which containers are running
$ podman ps
Output result
$ podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e5558cfdda7d registry.access.redhat.com/ubi8/httpd-24:latest /usr/bin/run-http... 9 minutes ago Up 23 seconds 0.0.0.0:8080->8080/tcp myapp
Show all containers, including stopped ones
$ podman ps --all
Output result
$ podman ps --all
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e5558cfdda7d registry.access.redhat.com/ubi8/httpd-24:latest /usr/bin/run-http... 10 minutes ago Up About a minute 0.0.0.0:8080->8080/tcp myapp
f6218c8fd423 registry.access.redhat.com/ubi8/httpd-24:latest /usr/bin/run-http... 5 minutes ago Exited (137) 2 minutes ago 0.0.0.0:8081->808080/tcp myapp1
(This content corresponds to Chapter 2.1.6)
Use podman inspect
to inspect containers.
Inspect the myapp container.
$ podman inspect myapp
Output result
$ podman inspect myapp
[
{
"Id": "e5558cfdda7d1c2c49c4d5ae59bbfcece64cb219b848ba78ae6cbba787ee8d07",.
"Created": "2023-09-03T19:58:13.302930658Z", "Path": "container-entry", "container-entry".
"Args": [
"/usr/bin/run-httpd"
],.
...
]
(This content corresponds to Chapter 2.1.7)
Remove myapp1 container
$ podman rm myapp1
Output result
$ podman rm myapp1
myapp1
(This content corresponds to Chapter 2.1.8)
Create an html file in the myapp container
$ podman exec -i myapp bash -c 'cat > /var/www/html/index.html' << _EOF
<html>
<head>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>
_EOF
Check file in container
$ podman exec myapp cat /var/www/html/index.html
Output result
$ podman exec myapp cat /var/www/html/index.html
<html>
<head>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>
(WIP)