Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update the limitation of memory/CPU for existing container in docker

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?

like image 931
Yuwen Yan Avatar asked Jan 07 '16 12:01

Yuwen Yan


People also ask

How do I change the memory limit on a Docker container?

Set Maximum Memory Access To limit the maximum amount of memory usage for a container, add the --memory option to the docker run command. Alternatively, you can use the shortcut -m . Within the command, specify how much memory you want to dedicate to that specific container.

Do Docker containers have a memory limit?

The maximum amount of memory the container can use. If you set this option, the minimum allowed value is 6m (6 megabytes). That is, you must set the value to at least 6 megabytes.

What happens when Docker container Hits memory limit?

The --memory parameter limits the container memory usage, and Docker will kill the container if the container tries to use more than the limited memory.


1 Answers

Docker Update Command

docker update --memory "1g" --cpuset-cpu "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}')
like image 95
oneklc Avatar answered Oct 10 '22 07:10

oneklc