Reputation: 4935
I do know that we can create a container with memory limitation like this
docker run -ti --memory-reservation 1G ubuntu:14.04 /bin/bash
but how to update the limitation of memory/CPU for existing container?
Upvotes: 28
Views: 26441
Reputation: 3154
docker update --memory "1g" --cpuset-cpus "1" <RunningContainerNameOrID>
this will update the "RunningContainerNameOrId" to use 1g of memory and only use cpu core 1
To up date all running containers to use core 1 and 1g of memory:
docker update --cpuset-cpus "1" --memory "1g" $(docker ps | awk 'NR>1 {print $1}')
Upvotes: 52
Reputation: 21
I'd have saved hours if even one person was running docker on WSL and mentioned that you need to do this from the .wslconfig file if you're running docker with wsl integration, on windows. I'm writing it right now for if another ME comes along and now they know the trick. https://itnext.io/wsl2-tips-limit-cpu-memory-when-using-docker-c022535faf6f
It's an old question, but if you come along and need this new answer, on that one platform, at least it'll get you thinking.
Upvotes: 2
Reputation: 15962
Dynamic resource allocation is currently not possible with only Docker. You would have to update the cpu/memory shares of the cgroup (control group). You must create a new container to change the resource limitations with Docker.
There is a Docker GitHub issue for dynamic resource configuration. This pull request suggests it will be added in Docker 1.10 with a docker set
or docker update
command. This command will allow you to update a container's configuration at runtime.
If you are running on a systemd
enabled system, you can leverage that as well to change the cpu or memory shares. An example can be found in this blog post.
Upvotes: 2