ps: command not found in a Docker container (how to install ps)
Codemia Knowledge Hub ·
The ps command fails inside most Docker containers because minimal base images do not include the procps package. Install it with your image's package manager: apt-get install -y procps on Debian or Ubuntu, apk add procps on Alpine. Often you do not need it at all, because docker top, docker stats and /proc give you the same information.
Why ps is missing
Docker images are built to be small. Base images like alpine, distroless, scratch, and the slim variants of debian or ubuntu strip out utilities the application does not strictly need. ps belongs to the procps package (procps-ng on some distributions), which is not considered essential for running a containerized application.
The trade-off is deliberate:
| Benefit | Impact |
| Smaller attack surface | Fewer binaries means fewer potential vulnerability vectors |
| Faster pulls and deploys | Less data to transfer over the network |
| Faster startup | Less filesystem overhead during container initialization |
| Lower storage costs | Especially significant when running hundreds of containers |
Installing ps in the Dockerfile
Install procps in the Dockerfile, not interactively in a running container. Interactive installs are lost when the container stops.
Debian / Ubuntu
--no-install-recommends avoids pulling in unnecessary packages, and rm -rf /var/lib/apt/lists/* removes the package index cache so the image stays small.
Alpine
--no-cache avoids storing the package index locally.
Amazon Linux / CentOS / RHEL
On these distributions the package is called procps-ng, not procps. Using the wrong name gives a "package not found" error.
Package names by distribution
| Base Image | Package Manager | Package Name | Install Command |
| Ubuntu / Debian | apt | procps | apt-get install -y procps |
| Alpine | apk | procps | apk add procps |
| Amazon Linux / CentOS / RHEL | yum/dnf | procps-ng | yum install -y procps-ng |
| Fedora | dnf | procps-ng | dnf install -y procps-ng |
| Arch Linux | pacman | procps-ng | pacman -S procps-ng |
Temporary install in a running container
For a one-off debugging session you can install procps in a running container. The change disappears when the container stops.
After that, ps works for the rest of that container's lifetime.
Getting process information without installing anything
Docker can show process information from the host without modifying the container.
docker top
This lists the processes running inside the container, like ps, but runs from the host. You can pass custom ps options:
docker stats
This shows real-time CPU, memory, network and I/O statistics for running containers, which is more useful than ps for monitoring resource usage.
Reading /proc directly
The /proc filesystem is always available inside Linux containers, even without procps. For a quick check, reading /proc/1/cmdline or /proc/1/status is faster than installing a package:
nsenter from the host
For containers that do not even have a shell, use nsenter on the host to enter the container's PID namespace and run the host's ps against a private /proc for that namespace:
This is the option for distroless or scratch images where installing packages is not possible.
Debug containers in Kubernetes
In Kubernetes, an ephemeral debug container lets you inspect a pod without changing it:
The debug container shares the process namespace of the target container, so you can run diagnostic tools without touching the application image.
Keeping debug tools out of production images
Every extra binary increases the attack surface. If you need ps during development but not in production, use a multi-stage build:
The production image stays lean while the build stage has the tools you need.
Alternatively, define a separate debug build target:
Related reading
- Pull a local image to run a pod in Kubernetes
- pull access denied repository does not exist or may require docker login
- Pulling an Image from Private Registry in Kubernetes cronjob fails
- Pulling from private registry fails - Unsupported docker v1 repository request
- PUB/SUB pattern in ZeroMQ not working
- Pushing to Git returning Error Code 403 fatal HTTP request failed
- Pulling images from private registry in Kubernetes
- Pulling local repository docker image from kubernetes
System design interview problems on this topic
- Design a Container Orchestration System: solution and walkthrough
- Design a Code Deployment System: solution and walkthrough
- Design GitHub Actions: solution and walkthrough
- Design a Serverless Architecture Framework: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.