619

I want to do a ps command in a docker container derived from Debian official Docker hub repository:

$ docker run -ti debian:wheezy /bin/bash
root@51afd6b09af8:/# ps
bash: ps: command not found

7 Answers 7

1023

ps is not installed in the base wheezy image. Try this from within the container:

apt-get update && apt-get install procps

or add the following line to the Dockerfile:

RUN apt-get update && apt-get install -y procps && rm -rf /var/lib/apt/lists/*
15
  • 16
    If you get this error "The command '/bin/sh -c apt-get install procps' returned a non-zero code: 1" then use apt-get install -y procps instead.
    – fred271828
    Commented Aug 25, 2017 at 17:25
  • 2
    Here is the URL that discussed in 2014 of not including ps in wheezy image: https://github.com/moby/moby/issues/447#issuecomment-36647268
    – daparic
    Commented Jan 29, 2019 at 5:11
  • 1
    RUN apt-get update && apt-get install -y procps && rm -rf /var/lib/apt/lists/*
    – Zhuo YING
    Commented Nov 25, 2019 at 7:51
  • 3
    Remove RUN from your command, I think it is a typo.
    – tjurkan
    Commented Oct 1, 2020 at 7:40
  • 3
    My edit has been rejected, apparently. I don't know why, but running RUN apt-get update && apt-get install -y procps within a running container will not lead to nothing else than an error. The original post, which was also the accepted answer, was fine as it was.
    – nnsense
    Commented Aug 3, 2021 at 10:33
162

use docker top

docker top <container ID>
3
  • 8
    Great answer! Eliminates the need to install procps on the container. Thanks. Commented Feb 21, 2022 at 5:19
  • The reason why one would ask for ps is to check if something is running inside the container or not. So the guy usually would go docker run smth /bin/bah and then ps. If nothing is running docker exits. With smth like --rm the evidence of process gone and this command does not work for obvious reasons for stopped containers. It can be a workaround if smth's working otherwise not an option for investigation.
    – Nick Roz
    Commented Sep 27, 2023 at 17:53
  • NOTE: docker top <container ID>shows the PID of the reflected process in the host computer, not the PID of the internal processes inside the container, as you can see executing cd /proc/; ls -ld [1-9]* Commented Feb 26 at 16:01
113

In case you can't install the procps package (don't have proper permissions) you can use /proc directory.

The first few directories (named as numbers) are PIDs of your processes. Inside directories, you can find additional information useful to decipher which process is connected to each PID. For example, you can use the cat command to view "cmdline" file to check which process is connected to PID.

$ ls /proc
1 10 11 ...

$ ls -1 /proc/22
attr
autogroup
auxv
cgroup
clear_refs
cmdline
...

$ cat /proc/22/cmdline 
/bin/sh

Edited - spaces are lost in the cmdline so we can pipe the cat output to the tr command, for example:

$ cat /proc/1/cmdline | tr '\0' ' '
/sbin/init splash
2
  • 20
    While not as convenient, this seems the more appropriate answer.
    – Jairus
    Commented May 29, 2020 at 5:32
  • 3
    To see the spaces I had to run "cat /proc/22/cmdline | xargs -0"
    – mgershen
    Commented Dec 13, 2021 at 14:27
25

If you're running a CentOS container, you can install ps using this command:

yum install -y procps

Running this command on Dockerfile:

RUN yum install -y procps
19

Firstly, run the command below:

apt-get update && apt-get install procps

and then run:

ps -ef
0
7

Kali users fix for bash: ps: command not found issue is:

apt install procps
1

For RockyLinux 9, you need to use this command

$> yum install procps-ng
1
  • Works for CentOS 9 as well.
    – liorko
    Commented Jul 17, 2023 at 8:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.