0
0
Dockerdevops~5 mins

CPU limits and reservations in Docker - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What are CPU shares in Docker?
CPU shares define the relative priority or weight for CPU allocation among containers when the host CPU is contended. Default value is 1024; higher shares get more CPU proportionally.
Click to reveal answer
beginner
What does setting a CPU limit do for a Docker container?
A CPU limit sets the maximum CPU resources a container can use (e.g., via --cpus). It prevents the container from using more than the limit, protecting other containers and the host.
Click to reveal answer
intermediate
How do you specify CPU shares using the Docker run command?
Use the option --cpu-shares followed by a number (default 1024), for example: docker run --cpu-shares=512 myimage gives half the priority of default.
Click to reveal answer
intermediate
Explain the difference between CPU shares and CPU quota in Docker.
CPU shares set relative priority for CPU time among containers when CPU is contended (no hard limit). CPU quota (with --cpu-quota and --cpu-period) sets an absolute limit on CPU usage time.
Click to reveal answer
beginner
What happens if a container tries to use more CPU than its limit?
Docker will throttle the container's CPU usage using CFS quota, ensuring it does not exceed the set limit and protecting other containers and the host system.
Click to reveal answer
Which Docker option sets the relative CPU priority for a container?
A--cpuset-cpus
B--cpu-quota
C--cpus
D--cpu-shares
What does the Docker --cpu-quota option control?
ANumber of CPU cores assigned
BMaximum CPU time a container can use per period
CRelative CPU priority among containers
DMinimum CPU guaranteed to a container
If no CPU limits are set, what happens when multiple containers compete for CPU?
AContainers with more CPU shares get more CPU
BCPU is shared equally by default
CThe first container gets all CPU
DContainers are throttled automatically
How do you limit a container to use at most 2 CPUs using Docker run?
A--cpu-quota=2
B--cpu-shares=2
C--cpus=2
D--cpu-period=2
What is the effect of setting CPU shares to 1024 for a container?
AIt sets the container's CPU priority relative to others (default value)
BIt guarantees 1024 CPU cores
CIt limits the container to 1024 milliseconds of CPU time
DIt reserves 1024 CPUs for the container
Describe how CPU limits and shares work in Docker and why they are important.
Think about sharing a pizza: shares decide portions when fighting over slices, limits prevent taking the whole pie.
You got /4 concepts.
    Explain the difference between CPU shares, CPU quota, and --cpus in Docker.
    Shares are like voting weight, quota is a timer, --cpus is a simple cap on cores.
    You got /3 concepts.