ps command doesn't work in docker container

DebianDocker

Debian Problem Overview


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

Debian Solutions


Solution 1 - Debian

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/*

Solution 2 - Debian

use docker top

docker top <container ID>

Solution 3 - Debian

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

Solution 4 - Debian

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

Solution 5 - Debian

Firstly, run the command below:

apt-get update && apt-get install procps

and then run:

ps -ef

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionYves NicolasView Question on Stackoverflow
Solution 1 - Debianuser2105103View Answer on Stackoverflow
Solution 2 - Debianes cologneView Answer on Stackoverflow
Solution 3 - DebianVedran VidovicView Answer on Stackoverflow
Solution 4 - DebianDuff GantherView Answer on Stackoverflow
Solution 5 - Debianharun ugurView Answer on Stackoverflow