ps command doesn't work in docker container
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
The ps command fails inside Docker containers because most minimal base images do not include the procps package. The fix is straightforward: install procps using your image's package manager. On Debian/Ubuntu, run apt-get install -y procps. On Alpine, run apk add procps. However, there are better alternatives for process inspection in containers, and understanding why ps is missing leads to smarter container design decisions.
Why ps Is Missing
Docker images are built to be small. Base images like alpine, distroless, scratch, and slim variants of debian or ubuntu strip out utilities that are not strictly required to run the application. The ps command is part of the procps package (or procps-ng on some distributions), and it is not considered essential for running containerized applications.
This is intentional. Smaller images provide:
| 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 |
So while the missing ps command can be frustrating during debugging, it reflects a deliberate design trade-off.
Installing ps in the Dockerfile
The correct place to install procps is in the Dockerfile, not interactively inside a running container. Interactive installs are lost when the container stops.
Debian / Ubuntu
The --no-install-recommends flag avoids pulling in unnecessary packages. The rm -rf /var/lib/apt/lists/* line removes the package index cache, keeping the image small.
Alpine
The --no-cache flag avoids storing the package index locally, which saves space.
Amazon Linux / CentOS / RHEL
On these distributions, the package is called procps-ng rather than procps.
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 Installation in a Running Container
For one-off debugging sessions, you can install procps inside a running container. This change is ephemeral and disappears when the container stops.
After installation, ps works for the remainder of that container's lifetime.
Alternatives to ps Inside Containers
Before installing procps, consider whether you actually need it. Docker provides several external tools that give you process information without modifying the container.
docker top
This shows processes running inside the container, similar to ps, but executed from the host. No installation required inside the container.
docker stats
This provides real-time CPU, memory, network, and I/O statistics for running containers. It is more useful than ps for monitoring resource usage.
Reading /proc directly
The /proc filesystem is always available inside Linux containers, even without procps installed. You can extract process information manually:
This approach works on any Linux container without installing anything.
nsenter from the host
For containers that do not even have a shell, you can use nsenter from the host to enter the container's namespace and run ps from the host's binaries:
This is particularly useful for distroless or scratch-based containers where installing packages is not an option.
Debug Containers in Kubernetes
In Kubernetes environments, ephemeral debug containers provide a clean way to debug without modifying the target pod:
This attaches a debug container that shares the process namespace of the target container. You can install and run diagnostic tools without changing the application container's image.
Multi-Stage Builds: Keep Production Images Clean
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 all the tools you need for debugging during development.
Alternatively, define separate Dockerfiles or build targets:
Common Pitfalls
- Installing packages interactively instead of in the Dockerfile. Interactive installs are lost when the container restarts. Always add package installations to the Dockerfile for persistence.
- Not cleaning up package caches. Failing to run
rm -rf /var/lib/apt/lists/*(Debian) or using--no-cache(Alpine) bloats the image layer with index data that is never used again. - Using the wrong package name. The package is
procpson Debian and Alpine butprocps-ngon CentOS, RHEL, Amazon Linux, and Fedora. Using the wrong name produces a "package not found" error. - Adding debug tools to production images. Every additional binary increases the attack surface. Use multi-stage builds to keep debug tools out of production.
- Forgetting about
docker top. Many developers installprocpsinside a container whendocker topfrom the host would have answered their question without any modification. - Ignoring
/proc. The proc filesystem is always available. For quick checks, reading/proc/1/cmdlineor/proc/1/statusis faster than installing a package.
Summary
- The
pscommand is missing from Docker containers because minimal base images exclude theprocpspackage to reduce image size and attack surface. - Install
procps(orprocps-ng) in your Dockerfile using the appropriate package manager for your base image. - For one-off debugging, install it interactively with
docker exec, but this change is lost when the container stops. - Prefer external tools like
docker topanddocker statswhen possible, as they require no changes to the container. - The
/procfilesystem andnsenterprovide process information without any package installation. - Use multi-stage builds to include debug tools in development images while keeping production images clean.
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 Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.