Running ps inside a container says command not found
ps: command not foundShort answer
Slim Debian and Ubuntu images do not ship the procps package, and ps comes from procps. Install procps in the image, or skip the install and run docker top from the host, which lists the container's processes without needing ps inside it.
Fix it fast
1Find out which cause you have
Ask the shell whether ps exists in the container and which base image you are on.
docker exec my-container sh -c 'command -v ps; cat /etc/os-release | head -n 2'2Match what you see, then jump to its fix
What does the error look like?
ps: command not foundbash: ps: command not found
Cause 1 of 2
The image does not include the procps package
1Check
On Debian the ps program is part of the procps package, together with top, free, pgrep and kill. Minimal and slim images leave it out.
docker exec my-container dpkg -s procps2Fix
Add procps to the packages your Dockerfile installs, and clear the apt lists in the same layer.
FROM debian:12-slim
RUN apt-get update \
&& apt-get install -y --no-install-recommends procps \
&& rm -rf /var/lib/apt/lists/*3Verify
Rebuild, start a container and run ps.
docker build -t my-image .
docker run --rm my-image ps auxConfirmed by packages.debian.org
Cause 2 of 2
You only need to look at processes, not run ps in the image
1Check
docker top asks the daemon for the running processes of a container. It runs on the host, so the image needs nothing installed.
docker top my-container2Fix
Use docker top from the host. Extra arguments after the container name are passed to ps on the host.
docker top my-container -ef3Verify
The process list prints with the container's main process on top.
docker top my-containerConfirmed by docs.docker.com
How do I stop it coming back?
- Keep debugging tools out of production images, and use docker top from the host when you only need a process list.
- If a debug image needs ps, add procps to its Dockerfile once instead of installing it by hand in running containers.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Servers
ping is missing inside a Docker container
sh: 1: ping: not found
Base images such as ubuntu are minimal, so ping is simply not installed.
2 causes, each with a fixServers
Apache logs SIGWINCH and exits on its own
the httpd container stops although nothing crashed
SIGWINCH is Apache's graceful-stop signal.
2 causes, each with a fixServers
apt-get does not exist on this EC2 instance
sudo: apt-get: command not found
apt-get belongs to Debian and Ubuntu.
2 causes, each with a fixServers
sam local fails: Running AWS SAM projects locally requires Docker
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
sam local start-api and sam local invoke run your function inside a Docker container, so SAM stops if it cannot talk to Docker.
3 causes, each with a fixServers
bash warns that it cannot change the locale after you log in to a server
bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
The shell was told to use a locale that is not built on the server.
3 causes, each with a fixServers
Syntax error: redirection unexpected when a Bash script runs under sh
script.sh: 12: Syntax error: redirection unexpected
The operators <<< (here-string) and &> are Bash features.
3 causes, each with a fix