Memory and CPU limits get all the attention. The number of processes a container can start is another limit, and I think it is underused.
A buggy app that keeps spawning workers, or a plain fork bomb, can eat the process table of the whole host. With --pids-limit the container hits its own ceiling first:
docker run -d --pids-limit 200 --name web nginx
Once the container reaches 200 processes, new forks inside it fail, and the rest of your server carries on. The Docker reference describes the flag as tuning the container pids limit, with -1 for unlimited.
In a Compose file it is the pids_limit attribute on the service:
services:
web:
image: nginx
pids_limit: 200
How high? I’d look at what the container needs on a busy day and put the limit well above that. A small web server needs far fewer processes than a database or a big Java app, so there is no single number that fits every container.
Caveat: set it too low and the app fails in strange ways when it cannot start a new process. If a container starts acting up right after you add the limit, raise it before you go looking for other causes.
Further reading: docker container run reference, Compose file reference: services, On this site: add init: true when a container leaves zombie processes