Containerization¶
Genaral¶
Usage¶
Downloading container image¶
podman pull <IMAGE_NAME>:<IMAGE_TAG>
docker pull <IMAGE_NAME>:<IMAGE_TAG>
Example
To download python image version 3.12-slim:
podman pull python:3.12-slim
docker 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>
docker run <IMAGE_NAME>:<IMAGE_TAG>
Example
Run container based on python image version 3.12-slim.
podman run python:3.12-slim
docker 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>
docker 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
docker run --name test_python_containerpython:3.12-slim
Execute a command inside a container¶
podman run <IMAGE_NAME>:<IMAGE_TAG> <CMD>
docker 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
docker run python:3.12-slim python --version
Enter container’s CLI (command line interface):¶
podman run -it <IMAGE_NAME>:<IMAGE_TAG> <CMD>
docker run -it <IMAGE_NAME>:<IMAGE_TAG> <CMD>
Example
enter bash CLI inside a python based container.
podman run -it python:3.12-slim bash
docker run -it python:3.12-slim bash
Expose container port:¶
podman run -p <HOST_PORT>:<CONTAINER_PORT> <IMAGE_NAME>:<IMAGE_TAG>
docker 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
docker run -p 8880:8888 python:3.12-slim
Managing containers¶
Display (list) running containers¶
podman ps
docker ps
Display all containers¶
This also displays exited (stopped) containers.
podman ps -a
docker ps -a
Managing images¶
Viewing locally available (downloaded) images¶
podman images
docker 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).