Skip to main content

Resource management

Overview

Managing resource consumption is crucial when running containerized applications, especially in environments with limited CPU and memory availability, such as edge computing nodes. Docker provides mechanisms to control the amount of CPU and memory that a container can use. In this tutorial, we will explore how to set resource limits in a docker-compose.yaml file and go through a practical example using the Filebrowser image.

Configuring Resource Limits in docker-compose.yaml

Docker Compose allows you to specify resource constraints within the deploy.resources section under the services definition. This enables you to limit CPU and memory usage for individual containers, ensuring optimal performance and preventing a single container from monopolizing system resources.

Example Configuration

The following docker-compose.yaml file demonstrates how to limit CPU and memory usage for a Filebrowser container:

version: '3.8'

services:
filebrowser:
image: filebrowser/filebrowser:latest
ports:
- "8080:80"
deploy:
resources:
limits:
cpus: "0.5"
memory: "256M"
reservations:
cpus: "0.25"
memory: "128M"

Explanation:

  • Limits:
    • cpus: "0.5": Restricts the container to use a maximum of 50% of a CPU core.
    • memory: "256M": Limits the container to 256MB of RAM.
  • Reservations:
    • cpus: "0.25": Guarantees at least 25% of a CPU core for the container.
    • memory: "128M": Ensures the container has at least 128MB of RAM available.

Summary

By specifying resource limits in the docker-compose.yaml file, you can prevent excessive resource consumption and ensure efficient operation of your containerized applications. This practice is especially useful for running applications on resource-constrained environments like edge nodes.