Can i configure docker to force all containers of the deamon to have the same ressources ? i want to limit memory and CPU for all containers and give them a default configuration at once not one by one
If you have multiple users using the same Docker daemon and you want them to all set resource limits, you could try Open Policy Agent
but containers can be very different. It would be hard to find a good default for all.
Hi, thanks for your response. Iām using Docker on a machine with limited resources. I want to restrict the resources available to each container so that no container can monopolize all available resources and affect other containers. Instead of configuring each container individually, Iām looking to apply the same configuration to all containers created within the same Docker. Is it possible to define this configuration globally for all containers in Docker ? or set a maximal value for each ressource, for example maximize consumption memory to 1GB for all containersā¦
I shared the OPA link because there is no default limit for all containers as far as I know. Thatās why I wrote this too:
If you have to override the limits every time, it doesnāt help setting a default. If in your special case you know you run containers from the same image or you know all containrs use about the same amount of resources, you can write wrapper scripts for docker and for docker compose as well. For the docker command, you would need to check the cli parameters passed to the wrapper script and add the default cpu limits if those parameters were not added. I actually donāt remember whether the same parameter passed the second time would override the first, but you can test it and depending on how it works, you might not need to check the passed parameters at all.
For Docker Compose, you would need to create a wrapper script that recognizes the parameters setting the compose file, parse the yaml file and generate an override file that can be passed to the compose command, but it would be easier to define the limits in the compose projects.
Maybe you can create a compose project template folder and initialize each project from there.
Hi again, Thanks i think the wrapper script solution will help, it works for now, i set max resources to all running containers, and the script that i wrote will be executed each x time to check resources again. Thanks for your help.