Mark Oliver's World

Posted: 11/09/2023

Dynamically Changing Docker Container Limits

We have limits set on our docker containers to limit things like CPU usage, and memory usage.

These are defined in docker compose configuration YAML files, and are set at runtime.

For instance, this setting sets the CPU to only be 95% of the available CPUs, and limit the Memory to 5000MB

Docker Compose picture showing the deploy resources options

This can be changed dynamically without the container being restarted using the docker update command:

https://docs.docker.com/engine/reference/commandline/container_update/

So if we run

docker update -m 700M test-messagebroker-1

This will change the memory limit from 5000M to 700M without the container being restarted.

Note this is a temporary change until the container is restarted, as the compose file will always take precedence on startup.


Thanks for reading this post.

If you want to reach out, catch me on Twitter!

I am always open to mentoring people, so get in touch.