LinuxCommandLibrary

docker-container-top

Display process information inside a Docker container

TLDR

Display the running processes of a container

$ docker [[top|container top]] [container]
copy

Display help
$ docker [[top|container top]] --help
copy

SYNOPSIS

docker-container-top [--no-trunc] CONTAINER [ps OPTIONS]

PARAMETERS

--no-trunc
    Disable output truncation for long fields

CONTAINER
    Name or ID of the target container

ps OPTIONS
    Pass-through options from ps command (e.g., -aux, -eo pid,%cpu,cmd)

DESCRIPTION

The docker-container-top command displays a dynamic, real-time list of running processes inside a specified Docker container, akin to the Unix top utility. It shows key metrics like PID, user, CPU time, memory usage, and command for each process, refreshing the display every few seconds for ongoing monitoring.

This tool is essential for container diagnostics, helping identify resource hogs, zombie processes, or anomalies in containerized apps without entering the container via docker exec. It leverages the container runtime's process namespace to fetch data from /proc, ensuring isolation from host processes.

By default, output includes standard columns (PID, USER, TIME, CMD), but users can append ps options for customization, such as sorting by memory (-o %mem) or showing all threads. Ideal for DevOps workflows in Docker Compose, Swarm, or Kubernetes with Docker runtime.

Requires a running container; stopped or exited ones yield no output. On Linux hosts, it's highly efficient; compatibility varies on other platforms.

CAVEATS

Works only on running containers.
Refresh rate fixed (~3s), no interactive sorting.
Dependent on host ps and container runtime support.
Not for Windows/Mac Docker without Linux VM.

COMMON EXAMPLES

docker-container-top myapp
Default top view.

docker-container-top myapp -aux
All processes, user-oriented.

docker-container-top myapp -eo pid,ppid,%cpu,%mem,cmd
Custom CPU/memory columns.

OUTPUT COLUMNS

Typical: PID (process ID), USER (owner), TIME (CPU time), CMD (command).
Customizable via ps -o headers.

HISTORY

Introduced in Docker 0.7.0 (2014) as docker top; evolved with full ps integration by Docker 1.12. Remains stable in Docker CLI v20+ for container introspection.

SEE ALSO

top(1), ps(1), htop(1), docker stats

Copied to clipboard