Key Points
Introduction to Containers
- Containers package an application with its dependencies into a portable, self-contained unit that runs consistently across different systems.
- Unlike virtual machines, containers share the host’s Linux kernel, making them lightweight and fast to start.
- Linux namespaces and cgroups provide the isolation and resource control that containers rely on.
- Container images are built from read-only layers; a thin writable layer is added at runtime and is lost when the container is removed (although there are options for filesystem persistence).
- On MacOS and Windows, containers run inside a lightweight Linux virtual machine managed by the container engine.
- Podman is a daemonless, open source container engine whose commands are largely interchangeable with Docker.
Getting Started
-
podman --versionconfirms that Podman is installed and accessible from the command line. - On MacOS and Windows, Podman requires a lightweight Linux virtual
machine, initialised with
podman machine initand started withpodman machine start. - On Linux and Windows Subsystem for Linux (WSL), Podman runs natively and no virtual machine is needed.
- Podman operates in rootless mode by default, meaning it does not require administrator privileges.
Managing Containers
-
podman container list -ashows all containers including stopped ones whilstpodman container listshows only running containers. - An exit code of
0means a container completed successfully, whereas a non-zero exit code indicates an error. -
podman runalways creates a new container, andpodman container startrestarts an existing stopped container. - The
-p host-port:container-port/protocoloption maps a port inside a container to a port on the host, enabling access to services running in the container. - The
-dflag runs a container in detached (background) mode. -
podman logs <name>retrieves its output. -
podman exec -ti <container> /bin/bashopens an interactive shell inside a running container. - The
-v <host-dir>:<container-dir>option mounts a host directory into the container, allowing both to access the same files. - All containers based on an image must be removed before that image can be deleted.
(Optional) Container Registries
-
podman infodisplays Podman’s full configuration, including which registries are configured for searching. - On macOS and Windows, Docker Hub is configured as a search registry by default; on Linux this typically requires manual configuration.
- Registry search is configured by editing
~/.config/containers/registries.conf. -
podman search <term>returns images from all configured registries whose names or descriptions match the search term.