What does setting a CPU reservation in a Docker container do?
Think about what 'reservation' means in real life, like reserving a seat but not limiting others from using more if available.
CPU reservation in Docker is a soft guarantee. It reserves CPU cycles for the container but does not prevent it from using more if available. It ensures minimum CPU availability but does not limit maximum usage.
What is the effect of running this command?
docker run --cpus=0.5 alpine top
Consider what '--cpus' means as a limit, not a reservation.
The '--cpus=0.5' flag limits the container to use at most half of one CPU core. It cannot exceed this limit but may use less.
A Docker container is started with --cpu-shares=512 but it uses more CPU than expected. What is a likely cause?
Check if CPU quota or CPU shares are being used for limiting CPU.
CPU shares provide relative weighting but do not enforce strict limits. If CPU quota is not set properly, the container can exceed expected CPU usage.
Which snippet correctly sets a CPU limit of 1.5 CPUs and a CPU reservation of 0.5 CPUs in a Docker Compose file?
services:
app:
image: myapp
deploy:
resources:
limits:
cpus: '1.5'
reservations:
cpus: '0.5'Check the string format and values for limits and reservations.
The correct syntax uses strings for CPU values and sets limits higher than reservations to reserve less CPU than the max allowed.
What is the best practice when setting CPU reservations for containers in a production environment?
Think about balancing guaranteed resources and flexibility.
Setting CPU reservations lower than limits guarantees minimum CPU availability but allows containers to use more CPU when available, improving resource utilization.