Podman: Fundamentals

Container Management

Creating and Running Containers

  • Running a container interactively:
    podman run -it --rm alpine sh
  • Running a detached container:
    podman run -d -p 8080:80 nginx
  • Assigning a name to a container:
    podman run --name mycontainer -d nginx

Stopping and Restarting Containers

  • Listing running containers:
    podman ps
  • Stopping a container:
    podman stop <container_id>
  • Restarting a stopped container:
    podman start <container_id>
  • Removing a container:
    podman rm <container_id>

Image Management

Pulling and Pushing Images

  • Pull an image from a registry:
    podman pull nginx
  • List downloaded images:
    podman images
  • Remove an image:
    podman rmi nginx
  • Push an image to a registry:
    podman push myimage:latest docker.io/myrepo/myimage:latest

Building Images with Podman

  • Writing a simple Dockerfile:
    FROM alpine
    CMD ["echo", "Hello, Podman!"]
  • Building an image:
    podman build -t myimage .
  • Running the newly built image:
    podman run myimage

Managing Container Images with Podman

Tagging and Inspecting Images

  • Tagging an image:
    podman tag myimage:latest myrepo/myimage:v1
  • Inspecting an image:
    podman inspect myimage

Saving and Loading Images

  • Saving an image as a tar file:
    podman save -o myimage.tar myimage:latest
  • Loading an image from a tar file:
    podman load -i myimage.tar

Container Lifecycle Management

Container States

  • Running: Container is active and executing.
  • Stopped: Container has been stopped.
  • Exited: Container has completed execution.
  • Paused: Container is temporarily halted but still exists.
  • Created: Container has been defined but not started.

Managing Persistent Containers

  • Restarting a container on boot using systemd:
    podman generate systemd --new --files --name mycontainer
  • Viewing container logs:
    podman logs mycontainer
  • Checking container status:
    podman ps -a

Hands-on Exercises

1. Create and Manage a Web Server Container

podman run -d --name webserver -p 8080:80 nginx
podman ps
podman logs webserver

2. Build and Run a Custom Container Image

echo -e "FROM alpine\nCMD [\"echo\", \"Hello Podman!\"]" > Dockerfile
podman build -t hello-podman .
podman run hello-podman

3. Push an Image to a Registry

podman tag hello-podman docker.io/myrepo/hello-podman:v1
podman push docker.io/myrepo/hello-podman:v1

Summary & Next Steps

Key Takeaways

  • Podman provides a powerful way to create, run, and manage containers.
  • Images can be pulled, built, and pushed to registries.
  • Container lifecycle management ensures smooth operation and debugging.

Next Module: Advanced Podman Concepts

In the next module, we will explore Podman Pods, container networking, persistent storage, and health checks.