A memory limit sets the maximum amount of memory a container can use. If the container tries to use more, it may be stopped or killed.
Click to reveal answer
beginner
What does memory reservation mean in Docker?
Memory reservation is the amount of memory that Docker guarantees to a container. It helps ensure the container has enough memory to run smoothly.
Click to reveal answer
beginner
How do you set a memory limit when running a Docker container?
Use the option --memory followed by the limit size, for example: docker run --memory=500m myimage limits memory to 500 megabytes.
Click to reveal answer
intermediate
What happens if a container exceeds its memory limit?
Docker may stop or kill the container to prevent it from using more memory than allowed, protecting the host system.
Click to reveal answer
intermediate
Why use memory reservation along with memory limits?
Memory reservation ensures the container has enough memory to run well, while the limit prevents it from using too much and affecting other containers.
Click to reveal answer
Which Docker option sets the maximum memory a container can use?
A--cpu-shares
B--memory
C--memory-reservation
D--memory-swap
✗ Incorrect
The --memory option sets the maximum memory limit for a container.
What does --memory-reservation do in Docker?
AGuarantees a minimum memory amount
BSets the maximum memory limit
CLimits CPU usage
DSets disk space limit
✗ Incorrect
--memory-reservation guarantees a minimum amount of memory for the container.
If a container exceeds its memory limit, what usually happens?
AIt gets more memory automatically
BIt slows down but keeps running
CDocker stops or kills the container
DNothing happens
✗ Incorrect
Docker stops or kills containers that exceed their memory limits to protect the host.
Which is true about memory reservation?
AIt is the minimum memory guaranteed
BIt sets disk quota
CIt controls CPU priority
DIt is the maximum memory allowed
✗ Incorrect
Memory reservation guarantees a minimum amount of memory for the container.
How do you limit a container's memory to 1 gigabyte?
Adocker run --memory-reservation=1g ...
Bdocker run --memory-swap=1g ...
Cdocker run --cpu-shares=1g ...
Ddocker run --memory=1g ...
✗ Incorrect
Use --memory=1g to limit the container's memory to 1 gigabyte.
Explain the difference between memory limits and memory reservations in Docker.
Think about max vs guaranteed memory.
You got /4 concepts.
Describe how to set memory limits and reservations when running a Docker container.
Recall the Docker run command options.
You got /4 concepts.
Practice
(1/5)
1. What does setting a memory limit for a Docker container do?
easy
A. It sets the maximum memory the container can use.
B. It sets the minimum guaranteed memory for the container.
C. It disables memory usage for the container.
D. It sets the CPU usage limit for the container.
Solution
Step 1: Understand memory limit concept
A memory limit restricts the maximum RAM a container can consume to avoid overuse.
Step 2: Compare with other options
Memory reservation is the soft minimum, CPU limit is unrelated, disabling memory is invalid.
Final Answer:
It sets the maximum memory the container can use. -> Option A
5. You want to run a container that should always have at least 1GB of memory available but never use more than 2GB. Which Docker run options correctly enforce this?
hard
A. docker run --memory=1g --memory-reservation=2g mycontainer
B. docker run --memory-reservation=1g --memory=2g mycontainer
C. docker run --memory=2g --memory-reservation=1g mycontainer
D. docker run --memory-reservation=2g --memory=1g mycontainer
Solution
Step 1: Identify memory reservation and limit roles
Memory reservation sets soft minimum (1GB), memory limit sets hard max (2GB).
Step 2: Match options to roles
docker run --memory=2g --memory-reservation=1g mycontainer correctly sets --memory=2g (max) and --memory-reservation=1g (min).
Final Answer:
docker run --memory=2g --memory-reservation=1g mycontainer -> Option C
Quick Check:
Limit=2g, Reservation=1g for min and max [OK]
Hint: Memory limit is max, reservation is min; order matters [OK]
Common Mistakes:
Swapping limit and reservation values
Setting reservation higher than limit
Confusing units or flags
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.