How to create custom images with Podman
Jack Wallen walks you through the steps for creating custom images for Podman deployments with the commit command.
Podman is a near 1:1 replacement for the Docker container engine. Although they are quite different underneath the hood, on top of it all they are quite similar. One thing they can both do is empower you to build your images to be used for custom container deployments. This means you can pull down an official image and then commit your changes so that image can be re-used for more custom deployments.
SEE: Hiring kit: Back-end Developer (TechRepublic Premium)
I’m going to show you how this is done by way of the official Ubuntu image that will be pulled down from docker.io. By doing this you can customize the Ubuntu image to your exact specifications and then deploy new containers based on the changed image.
What you’ll need to create a custom image with Podman
To follow along, you’ll need an operating system that supports Podman such as Rocky Linux, AlmaLinux, RHEL or CentOS.
How to pull the Ubuntu image
The first thing we’ll do is pull the latest Ubuntu image from Docker.io. To do that, log in to your Linux distribution, open a terminal window and issue the command:
podman pull ubuntu:latest
How to deploy and modify a container with the image
Next, we need to deploy a container with our newly pulled image. This can be achieved with:
podman run -ti --name ubuntu-dev ubuntu:latest
You should find yourself at the bash prompt of the newly running container.
Update apt with:
We’ll now install the NGINX web server with the command:
apt-get install nginx -y
You can install any other applications you want. For example, if you’ll need to do Java development, install the latest JRE with:
apt-get install default-jre -y
How to create your new image
Exit from the running container with the exit command the then commit the changes to the running container with:
podman commit ubuntu-dev
Next, we need to locate the ID of the image with:
You should now see an image listed with the <non> label under REPOSITORY. That image should also have an associated ID, which will be a random string of characters. Copy that string and then tag the image with a new name like so:
podman tag ID ubuntu-dev-base
Where ID is the image ID.
You can tag the new image with any name you like. Now, when you issue the command podman images, you should see your newly-tagged image listed like this:
localhost/ubuntu-dev-base latest 4bdac71c4932 2 minutes ago 563 MB
If you want to deploy a container based on that new image, the command might look like this:
podman create --name ubuntu-web ubuntu-dev-base
And that’s all there is to create a custom image for your Podman deployments.
Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen.