0
0
Dockerdevops~20 mins

CPU limits and reservations in Docker - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
CPU Resource Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding CPU Reservations in Docker

What does setting a CPU reservation in a Docker container do?

ADisables CPU usage for the container
BLimits the container to never use more than the reserved CPU share
CGuarantees the container will always get the reserved CPU share even if the host is busy
DSets a soft limit that reserves CPU cycles for the container but does not restrict usage above it
Attempts:
2 left
💡 Hint

Think about what 'reservation' means in real life, like reserving a seat but not limiting others from using more if available.

💻 Command Output
intermediate
2:00remaining
Output of Docker Run with CPU Limit

What is the effect of running this command?

docker run --cpus=0.5 alpine top
AThe container can use up to 50% of one CPU core
BThe container is limited to 0.5 CPU cores but can burst above if available
CThe container is guaranteed 0.5 CPU cores minimum
DThe container will use exactly 0.5 CPU cores at all times
Attempts:
2 left
💡 Hint

Consider what '--cpus' means as a limit, not a reservation.

Troubleshoot
advanced
2:00remaining
Troubleshooting CPU Limit Not Enforced

A Docker container is started with --cpu-shares=512 but it uses more CPU than expected. What is a likely cause?

AThe host has multiple CPU cores, so the container can use more than one core
BThe container is using CPU shares instead of CPU quota, so limits are not enforced
CDocker does not support CPU limits on the host operating system
DThe CPU limit flag was ignored because the container is running in privileged mode
Attempts:
2 left
💡 Hint

Check if CPU quota or CPU shares are being used for limiting CPU.

🔀 Workflow
advanced
2:00remaining
Configuring CPU Limits and Reservations in Docker Compose

Which snippet correctly sets a CPU limit of 1.5 CPUs and a CPU reservation of 0.5 CPUs in a Docker Compose file?

Docker
services:
  app:
    image: myapp
    deploy:
      resources:
        limits:
          cpus: '1.5'
        reservations:
          cpus: '0.5'
A
limits:
  cpus: '1.5'
reservations:
  cpus: '0.5'
B
limits:
  cpus: 1.5
reservations:
  cpus: 0.5
C
limits:
  cpus: 1
reservations:
  cpus: 1
D
limits:
  cpus: '0.5'
reservations:
  cpus: '1.5'
Attempts:
2 left
💡 Hint

Check the string format and values for limits and reservations.

Best Practice
expert
2:00remaining
Best Practice for Setting CPU Reservations in Production

What is the best practice when setting CPU reservations for containers in a production environment?

AAvoid setting CPU reservations to let the container use any available CPU freely
BSet CPU reservations equal to CPU limits to guarantee exact CPU usage
CSet CPU reservations lower than CPU limits to ensure minimum guaranteed CPU while allowing bursts
DSet CPU reservations higher than CPU limits to prioritize the container
Attempts:
2 left
💡 Hint

Think about balancing guaranteed resources and flexibility.