WittCode💻

Why So Few Processes?

By

Docker containers don't run many processes. Learn why and how to analyze process usage in a container.

Table of Contents 📖

Inspecting a Container

In a Docker container, there are usually very few processes running. Consider the following Dockerized Node app (container name wb-server-c):

docker exec -it wb-server-c ps -e
PID   USER     TIME  COMMAND
    1 root      3:19 node src/server.js
   44 root      0:00 ps -e

INFO: PID 1 is usually the main process (node src/server.js).

The command ps -e in Linux shows all running processes on the system, across all users. ps stands for process status and -e means "all processes". Note how there are only two processes running: the main process (node src/server.js) and the command ps -e. Some reasons for this include:

  • Containers are designed to run a single main process (like a Node.js application).
  • There is no traditional init system (like systemd or init) running in most containers.
  • Processes inside a container are isolated and don't see the host's processes.

Why So Few Processes

Docker doesn't run many processes as containers don't run a full OS. Instead, they share the host's kernel. This is also the design of Docker. Instead of stuffing many processes into one container, each container runs a single process. Then you spin up as many containers as you need to handle each process.

Why So Few Processes?