0
0
Dockerdevops~30 mins

Memory limits and reservations in Docker - Mini Project: Build & Apply

Choose your learning style9 modes available
Memory Limits and Reservations in Docker
📖 Scenario: You are managing a Docker container that runs a small web application. To keep the container stable and prevent it from using too much memory on the host machine, you want to set memory limits and reservations.This helps the container run smoothly without affecting other applications on the same server.
🎯 Goal: You will create a Docker container with specific memory limits and memory reservation settings. This will ensure the container uses memory efficiently and respects the host's resources.
📋 What You'll Learn
Create a Docker container running the nginx image
Set a memory limit of 300MB for the container
Set a memory reservation of 150MB for the container
Verify the container is running with the correct memory settings
💡 Why This Matters
🌍 Real World
Setting memory limits and reservations helps keep Docker containers from using too much memory, which can slow down or crash other applications on the same server.
💼 Career
Understanding resource limits is important for DevOps roles to ensure applications run reliably in shared environments.
Progress0 / 4 steps
1
Create a Docker container running nginx
Write the Docker command to create and run a container named mynginx using the nginx image in detached mode.
Docker
Need a hint?

Use docker run with -d for detached mode and --name mynginx to name the container.

2
Add a memory limit of 300MB
Modify the Docker run command to add a memory limit of 300m using the --memory option.
Docker
Need a hint?

Use --memory 300m to limit the container memory to 300 megabytes.

3
Add a memory reservation of 150MB
Extend the Docker run command to include a memory reservation of 150m using the --memory-reservation option.
Docker
Need a hint?

Use --memory-reservation 150m to set the soft memory limit to 150 megabytes.

4
Verify the container memory settings
Write the Docker command to inspect the container mynginx and display only the memory limit and memory reservation values.
Docker
Need a hint?

Use docker container inspect with --format to show memory settings.