Understanding Memory Management in Containers with Podman

Jason Bell
3 min readFeb 23, 2024

Podman, a daemonless container engine for developing, managing, and running OCI Containers on your Linux System, has gained significant popularity for its ability to run containers without the need for a container daemon. After using Docker for so long I’ve been using Podman within development, staging and production environments.

This not only enhances security but also offers a more straightforward approach to container management. A critical aspect of effectively managing containers with Podman involves understanding and implementing efficient memory management strategies.

I’ve previously written about Docker memory management, so now it’s the turn of Podman.

Podman Memory Management

Memory management in containers is crucial for ensuring that applications run efficiently without exhausting the host system’s resources. Podman, like other containerisation tools, allows users to allocate, limit, and monitor the memory usage of containers. This capability is vital for preventing a single container from consuming excessive resources, which could impact other containers or the host system itself.

A lot of times I’ve seen very little thought go into memory management of containers, but after seeing systems grind to a halt, well I took a lot more notice.

Setting Memory Limits

Podman provides various options for setting memory limits on containers to control their resource consumption. The --memory (or -m) flag allows users to specify the maximum amount of memory the container can use. For instance, setting a limit of 256m ensures that the container cannot use more than 256 megabytes of RAM.

podman run -d --name example_container -m 256m my_image

This command starts a container with a memory limit of 256 MB, running in detached mode, you’ll get your terminal prompt back after the execution has started. Run podman ps to see the container status.

Swap Memory Management

In addition to RAM, Podman allows the configuration of swap memory for containers, which is particularly useful for systems that support swapping. The --memory-swap flag sets the total amount of memory and swap space that can be used. If this limit is reached, the container will not be allowed to allocate more memory, preventing it from affecting the performance of other containers or the host.

podman run -d --name example_container -m 256m --memory-swap 512m my_image

This configuration limits the container to 256 MB of RAM and 256 MB of swap, totaling 512 MB of memory.

Monitoring Memory Usage

Monitoring and managing memory usage is critical for maintaining container performance and system stability. Podman offers several ways to monitor the memory consumption of containers. The podman stats command provides real-time statistics about container resources, including CPU usage, memory usage, network I/O, and more.

podman stats

This command displays a live stream of resource usage statistics for all running containers.

Best Practices for Memory Management

  • Set realistic memory limits: Allocate sufficient memory to your containers to ensure smooth operation but be mindful of the host system’s total resources.
  • Monitor container performance: Regularly check the resource usage of your containers and adjust memory limits as necessary.
  • Optimise container applications: Within the container, ensure that applications are optimised for memory usage, which can reduce the overall resource requirements.
  • Utilise swap judiciously: While swap space can be helpful, relying too much on it can degrade performance. Use it as a buffer but not as the primary memory source.

Effective memory management is a cornerstone of running containers efficiently with Podman. By setting appropriate memory limits, monitoring usage, and adhering to best practices, developers and system administrators can ensure that their containers perform optimally without compromising the host system’s stability or other containers’ performance.



Jason Bell

A polymath of ML/AI, expert in container deployments and engineering. Author of two machine learning books for Wiley Inc.