Bird
0
0

How would you combine CPU limits with memory limits in a Docker Compose file to ensure a service uses at most 1 CPU and 512MB RAM, but reserves 0.5 CPU?

hard📝 Application Q9 of 15
Docker - Resource Management
How would you combine CPU limits with memory limits in a Docker Compose file to ensure a service uses at most 1 CPU and 512MB RAM, but reserves 0.5 CPU?
Aservices:\n app:\n image: myapp\n deploy:\n resources:\n limits:\n cpus: '1.0'\n memory: 512M\n reservations:\n cpus: '0.5'\n memory: 256M
Bservices:\n app:\n image: myapp\n cpu_limit: 1\n cpu_reservation: 0.5\n mem_limit: 512M
Cservices:\n app:\n image: myapp\n deploy:\n cpu: 1\n memory: 512M
Dservices:\n app:\n image: myapp\n resources:\n cpus: 1\n memory: 512M
Step-by-Step Solution
Solution:
  1. Step 1: Use Docker Compose deploy resources syntax

    CPU and memory limits and reservations are set under deploy.resources with limits and reservations.
  2. Step 2: Check option values and format

    services:\n app:\n image: myapp\n deploy:\n resources:\n limits:\n cpus: '1.0'\n memory: 512M\n reservations:\n cpus: '0.5'\n memory: 256M correctly sets CPU limits to 1, memory limits to 512M, CPU reservation to 0.5, and memory reservation to 256M (optional).
  3. Final Answer:

    Option A with deploy.resources limits and reservations correctly set. -> Option A
  4. Quick Check:

    Use deploy.resources with limits and reservations [OK]
Quick Trick: Set CPU and memory limits and reservations under deploy.resources [OK]
Common Mistakes:
  • Using invalid keys like cpu_limit in Compose
  • Omitting deploy.resources section
  • Incorrect YAML indentation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Docker Quizzes