Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

Running ps inside a container says command not found

Errorps: command not found

Short 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.

  • Applies to Docker Engine 28, debian 12 slim image, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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'
  2. 2Match what you see, then jump to its fix

    1. 1command -v prints nothing and os-release says Debian or UbuntuThe image does not include the procps packageFix
    2. 2You want a quick process list from a running container and do not want to change the imageYou only need to look at processes, not run ps in the imageFix

What does the error look like?

  • ps: command not found
  • bash: 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 procps

2Fix

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 aux

Confirmed by packages.debian.org

Did this fix it?

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-container

2Fix

Use docker top from the host. Extra arguments after the container name are passed to ps on the host.

docker top my-container -ef

3Verify

The process list prints with the container's main process on top.

docker top my-container

Confirmed by docs.docker.com

Did this fix it?

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

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.