DOCKER · Runtime · 8 min
Set explicit resource limits
Bound memory, CPU allocation, and the process count.
Not completedYour task
Run the named container with a 64 MiB memory limit, half a CPU, and a PID limit of 32. Confirm all three settings.
What you’re aiming for
- Memory is 67108864 bytes.
- NanoCpus is 500000000.
- PidsLimit is 32.
1. Prepare your practice folder
Use a running Docker engine in Linux container mode. The setup commands below use a Bash-compatible shell: Git Bash on Windows, or Bash on Linux/macOS.
Create a new, empty folder for this exercise. If that name already exists, choose another new name. Continue only after you’re inside the new folder.
mkdir opsrung-docker-set-resource-limits && cd opsrung-docker-set-resource-limits
Run these setup commands in that folder:
cat > Dockerfile <<'DOCKERFILE' FROM alpine:3.22 USER 65534:65534 CMD ["sleep","3600"] DOCKERFILE docker build -t opsrung-set-resource-limits:practice .
Docker may download the official Alpine image and, for the web task, its HTTP package. If an example container name already exists, use a different name consistently. If port 8088 is occupied, choose another free local port.
2. Try the task
Work toward the goal above. Start by inspecting the files or resources, then use a hint if you need one.
Hint 1
--memory accepts a size suffix.
Hint 2
--cpus is a quota, not a guarantee of CPU time.
Hint 3
Use --memory 64m --cpus 0.5 --pids-limit 32.
3. Review your result
Use these commands to look at your result and compare it with the goals. The website does not run or verify them.
docker inspect opsrung-set-resource-limits --format "{{.HostConfig.Memory}} {{.HostConfig.NanoCpus}} {{.HostConfig.PidsLimit}}"What you should see
- Memory is 67108864 bytes.
- NanoCpus is 500000000.
- PidsLimit is 32.
If your result differs: Compare the actual output with each goal. Keep your work inside this exercise’s folder and use only its named resources.
Compare with one possible solution
docker run -d --name opsrung-set-resource-limits --network none --read-only --cap-drop ALL --security-opt no-new-privileges --memory 64m --cpus 0.5 --pids-limit 32 opsrung-set-resource-limits:practice
Other approaches are fine if you reach the same goal. Opening this solution does not mark the exercise complete.
Clean up this exercise
Only remove the example resources you created. Volume cleanup deletes that exercise’s saved sample data. Keep anything you need.
docker stop opsrung-set-resource-limits docker rm opsrung-set-resource-limits docker image rm opsrung-set-resource-limits:practice
Finished this exercise?
You decide when you’re done. Your choice is saved in this browser, and you can change it later.