How to set up Podman

1. Quick Environment Setup

mkdir -p /podman/$USER/run
cd /podman/$USER
mkdir podman-lab

2. Create your Containerfile

Now you’ll define a container that serves files over HTTP using Python’s built-in server as an example

a. Enter your podman directory
cd podman-lab

b. Create a new Containerfile
nano Containerfile
c. Paste this into the file
FROM python:3.11-slim
WORKDIR /srv
EXPOSE 8000
CMD ["python", "-m", "http.server", "8000"]

Save and exit (in nano, press Ctrl + O, then Enter, then Ctrl + X).

 

3. Build and Run Your Container

Now it’s time to turn your Containerfile into a container image and run it.

a. Build the Container Image
podman build -t python-httpd .

-t python-httpd: gives your image a name or tag

.: tells Podman to use the current directory

c. Run the container
podman run -d --name mypythonhttpd -p 8000:8000 python-httpd

-d: Run in detached (background) mode

--name: Assigns a name to the container

-p: Maps host port 8000 to container port 8000

 

4. Run External Container Images

Using an exisiting container is usually more common. Podman can also run pre-built images from online registries like Docker Hub or Red Hat Registries

a. Example: Run an image directly from Docker Hub
podman run -it alpine sh

alpine: The image name (a minimal Linux distribution).

-it: Runs the container interactively with a shell.

sh: Starts a shell inside the container.

b. Example: Run a web server using NGINX
podman run -d --name mynginx -p 8080:80 nginx

-d: Runs in the background (detached).

--name: Assigns a name to the container.

-p 8080:80: Maps your host port 8080 to the container’s port 80.