Exploring Podman — HelloWorld container
In this blog, we will create a Containerfile/Dockerfile to pull an Oracle Linux 8-slim image and then echo “Hello World”.
Since this is just a base OS image the container will stop after it prints “Hello World”. We will also see how to keep this container running and then log in to the container.
Before we begin let me clear out all the pods and images from my machines using the following command:
podman system reset
Step 1:
Verify that there are no running/stopped containers:
podman ps -a
Step 2:
Verify that there are no images:
podman images
Step 3:
Create a Containerfile:
[opc@control ~]$ vi Dockerfile
FROM os/oraclelinux:8-slim
MAINTAINER Puneeth
CMD [“echo”, “Hello World”]
Step 4:
Build an image:
podman build -t hello_from_puneeth .
Step 5:
Now check the images:
podman images
Step 6:
Verify that build creates an image. A container is still not started using this image:
podman ps -a
Step 7:
Check the image tree:
podman image tree localhost/hello_from_puneeth
podman image tree localhost/hello_from_puneeth --whatrequires
Step 8:
Inspect the number of layers:
podman inspect localhost/hello_from_puneeth --format "{{len .RootFS.Layers}}"
Step 9:
Inspect the image:
podman inspect localhost/hello_from_puneeth
Step 10:
Since podman is running as a user with no root privileges the local store used to store images is “~/.local/share/containers”
Step 11:
Check history of image:
podman history localhost/hello_from_puneeth
Step 12:
We have confirmed that there are no running or stopped containers. Now let's start a container using the image created earlier:
podman ps -a
podman run -d --name hello localhost/hello_from_puneeth
Step 13:
Check the logs:
podman logs <container_id>
Step 14:
The container existed after printing the ‘Hello World’ message.
Let’s create a new container from the same image we created earlier and this time we keep the container running using the following command:
podman run -d — name hello1 localhost/hello_from_puneeth tail -f /dev/null
podman ps -a
Step 15:
Now let’s open a bash shell inside the container:
podman exec -it <container_id> /bin/bash
Step 16:
Check the resource utilization of POD:
podman top <container_ID>