Containerization

Genaral

Usage

Downloading container image

podman pull <IMAGE_NAME>:<IMAGE_TAG>

Example

To download python image version 3.12-slim:

podman pull python:3.12-slim

Running a container

To run container based on image <IMAGE_NAME> with tag <IMAGE_TAG> execute:

podman run <IMAGE_NAME>:<IMAGE_TAG>

Example

Run container based on python image version 3.12-slim.

podman run python:3.12-slim

Name a container

You can specify container name with --name option:

podman run --name "<CONTAINER_NAME>" <IMAGE_NAME>:<IMAGE_TAG>

Example

Run container based on python image version 3.12-slim and name it test_python_container.

podman run --name test_python_container python:3.12-slim

Execute a command inside a container

podman run <IMAGE_NAME>:<IMAGE_TAG> <CMD>

Example

Get version of python (run python --verion) inside the container:

podman run python:3.12-slim python --version

Enter container’s CLI (command line interface):

podman run -it <IMAGE_NAME>:<IMAGE_TAG> <CMD>

Example

enter bash CLI inside a python based container.

podman run -it python:3.12-slim bash

Expose container port:

podman run -p <HOST_PORT>:<CONTAINER_PORT> <IMAGE_NAME>:<IMAGE_TAG>

Example

App inside container is running on port 8888. If you want to access this app outside container with localhost:8880:

podman run -p 8880:8888 python:3.12-slim

Managing containers

Display (list) running containers

podman ps

Display all containers

This also displays exited (stopped) containers.

podman ps -a

Managing images

Viewing locally available (downloaded) images

podman images 

Building a container

To build a custom container image create a new folder create a Dockerfile file in that folder. (There can only be one Dockerfile file in any folder).

Build an image

Dockerfile

Compose

Compose file

Usage