brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: docker run --pids-limit stops one container from forking your server to death

Docker
~/tips/tip-docker-run-pids-limit

docker run -d --pids-limit 200 --name web nginx

Caps how many processes a container may start, so a runaway or fork bomb stays inside it.

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

More Docker tips ONBUILD RUN /usr/local/bin/python-build --dir /app/src SHELL ["/bin/bash", "-c"] docker commit <container> myname/testimage:version3 docker import /path/to/exampleimage.tgz docker compose events All Docker tips (192) All topics

Link