Bob Explores Linux Containers with Podman on AlmaLinux
Categories:
Bob’s next challenge was to dive into Linux containers using Podman, a daemonless container engine built for running, managing, and building containers. Containers allow for lightweight, portable applications, and Bob knew mastering them would future-proof his sysadmin skills.
“Containers are the future of IT—let’s get started with Podman!” Bob said enthusiastically.
Chapter Outline: “Bob Explores Linux Containers with Podman”
Introduction: What Are Containers?
- Overview of containerization.
- Podman vs. Docker.
Installing and Setting Up Podman
- Installing Podman on AlmaLinux.
- Configuring Podman for rootless operation.
Running and Managing Containers
- Pulling container images.
- Running and stopping containers.
Building Custom Container Images
- Writing a
Dockerfile
. - Building images with Podman.
- Writing a
Using Pods for Multi-Container Applications
- Understanding pods in Podman.
- Creating and managing pods.
Persisting Data with Volumes
- Creating and attaching volumes.
- Backing up container data.
Networking and Port Management
- Exposing ports for containerized services.
- Configuring container networks.
Automating Containers with Systemd
- Generating Systemd service files for containers.
- Managing containers as services.
Conclusion: Bob Reflects on Container Mastery
Part 1: Introduction: What Are Containers?
Bob learned that containers are lightweight, portable environments for running applications. Unlike virtual machines, containers share the host kernel, making them faster to start and use fewer resources.
Why Podman?
- Daemonless: Runs without a central daemon, unlike Docker.
- Rootless Mode: Allows non-root users to run containers securely.
- Docker-Compatible: Supports Dockerfiles and images.
“With Podman, I get the power of Docker without the baggage!” Bob said.
Part 2: Installing and Setting Up Podman
Step 1: Installing Podman
Install Podman:
sudo dnf install -y podman
Verify the installation:
podman --version
Step 2: Configuring Rootless Podman
Bob configured Podman to run without root privileges for added security:
sudo sysctl user.max_user_namespaces=28633
Log in as a regular user and test Podman:
podman info
“Podman is ready to go—time to run my first container!” Bob said.
Part 3: Running and Managing Containers
Step 1: Pulling Container Images
Search for an image:
podman search nginx
Pull the official
nginx
image:podman pull docker.io/library/nginx
Step 2: Running a Container
Run the
nginx
container:podman run -d --name webserver -p 8080:80 nginx
Check the running container:
podman ps
Access the containerized web server in a browser:
http://<server-ip>:8080
Step 3: Stopping and Removing Containers
Stop the container:
podman stop webserver
Remove the container:
podman rm webserver
“Containers make deploying services quick and easy!” Bob said.
Part 4: Building Custom Container Images
Step 1: Writing a Dockerfile
Bob created a Dockerfile
to build a custom nginx
image:
nano Dockerfile
Example
Dockerfile
content:FROM nginx:latest COPY index.html /usr/share/nginx/html/index.html
Step 2: Building the Image
Build the image with Podman:
podman build -t custom-nginx .
Verify the image:
podman images
“With custom images, I can tailor containers to my exact needs!” Bob said.
Part 5: Using Pods for Multi-Container Applications
Step 1: Understanding Pods
Bob learned that a pod groups multiple containers to share networking and storage.
Step 2: Creating and Managing Pods
Create a pod:
podman pod create --name mypod -p 8080:80
Add containers to the pod:
podman run -d --pod mypod nginx podman run -d --pod mypod redis
List pod containers:
podman ps --pod
“Pods make managing multi-container apps a breeze!” Bob said.
Part 6: Persisting Data with Volumes
Step 1: Creating a Volume
Create a volume:
podman volume create nginx-data
Step 2: Attaching the Volume
Run a container with the volume:
podman run -d --name webserver -v nginx-data:/usr/share/nginx/html nginx
Step 3: Backing Up Container Data
Back up the volume:
podman volume inspect nginx-data podman run --rm -v nginx-data:/data -v $(pwd):/backup busybox tar czvf /backup/nginx-data-backup.tar.gz /data
“Volumes keep my data safe even if containers are recreated!” Bob noted.
Part 7: Networking and Port Management
Exposing Ports
Bob exposed a container’s ports to make it accessible from outside:
podman run -d --name webserver -p 8080:80 nginx
Configuring Container Networks
List networks:
podman network ls
Create a custom network:
podman network create mynetwork
Run a container on the custom network:
podman run -d --name webserver --network mynetwork nginx
Part 8: Automating Containers with Systemd
Step 1: Generating Systemd Service Files
Generate a Systemd unit file for a container:
podman generate systemd --name webserver --files
Copy the generated file to the system directory:
sudo cp container-webserver.service /etc/systemd/system/
Step 2: Managing Containers as Services
Enable and start the service:
sudo systemctl enable container-webserver sudo systemctl start container-webserver
“With Systemd, I can manage containers just like regular services!” Bob said.
Conclusion: Bob Reflects on Container Mastery
Bob successfully learned to deploy, manage, and automate containers using Podman. With lightweight and portable containers, he was confident his AlmaLinux server was future-proofed for modern applications.
Next, Bob plans to explore Configuring Advanced Monitoring with Prometheus and Grafana on AlmaLinux.