Podman image from container

on mcot's blog

Create a new image from current container
#linux #podman

Let's say you need an image, based on the latest from NGINX, with PHP, build-essential, and nano installed. I'll walk you through the process of pulling the image, running the container, accessing the container, adding the software, and committing the changes to a new image that can then be easily used as a base for your dev containers.

Pulling the image and running the container:

podman pull nginx
podman run  -it --name nginx-template-base -p 8080:80 nginx

Modifying the container:

apt-get install nano
‚Äčapt-get install php5

Commit the changes:

podman commit CONTAINER_ID nginx-template

The newly created template is ready and you can run using:

podman run -it --name nginx-dev -p 8080:80 nginx-template

# Summary:

When creating a container always give it a name. It makes things easier.

For example, we've created a basic alpine container with all the apps that we need called alpine_bin. From this we'll create a image template alpine_template based on alpine_bin.

podman commit alpine_bin alpine-template

From newly created template alpine_template, spin up a new container alpine_dev using:

podman run -it --name alpine-dev alpine-template

# Backup the image

podman save -o backup-alpine-template.tar alpine-template

# Push it to the docker hub

podman login -u <user>
podman push <user>/<image> 
podman pull <user>/<image>

docker pull <user>/alpine-dev-template