Description
CPU and memory limits do not cap the number of processes and threads a container can create.
Potential impact
A faulty or malicious loop can create enough processes to exhaust host resources and disrupt other services.
Remediation
Measure the processes and threads the service needs and set a finite pids_limit. The value -1 means unlimited. Verify it alongside CPU and memory limits, and test that the workload can still start the processes and threads it needs.
Examples
The build context’s Dockerfile is omitted. The limit of 10 is an example.
Before
yaml
services:
auth:
build:
context: .
mem_limit: 500M
After
yaml
services:
auth:
build:
context: .
pids_limit: 10
mem_limit: 500M
Explanation:
- Before: The only limit shown is
mem_limit: 500M. - After: The service adds
pids_limit: 10and keeps its memory cap.