According to Docker documentation , in order to limit a container to a certain amount of cpu, we use the parameter --cpus
when starting the container:
docker run -it --cpus=".5" ubuntu /bin/bash
Now that I have the container running, how do I check that limit that was assigned to the container in the first place?
In other words, is there a command that I can run and I can see that .5
that was assigned to the ubuntu container of the example?
You can check the field NanoCpus
in docker inspect
command.
Specify how much of the available CPU resources a container can use. For instance, if the host machine has two CPUs and you set --cpus="1.5", the container is guaranteed at most one and a half of the CPUs. This is the equivalent of setting --cpu-period="100000" and --cpu-quota="150000". Available in Docker 1.13 and higher.
In your example, the NanoCpus
should be 500000000
(0.5 * 100000 * 10000)
The first command to check is docker container inspect
.
docker container inspect <container ID or name>|grep -i cpu
With --format
, you can even extract its value directly if exposed.
Then, at runtime, check docker stats
to see if, at runtime, the percentage of the host's CPU and memory the container is using.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.