brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: docker top lists the processes inside a container from the host

Docker
~/tips/tip-docker-top-container-processes

docker top mycontainer

Lists the processes running in a container without opening a shell inside it.

A container that eats CPU or never exits is a puzzle until you see what runs inside it. docker top shows the process list without a shell in the container.

docker top mycontainer
docker top mycontainer -ef

The reference describes it as docker container top CONTAINER [ps OPTIONS]. Without options you get a short table with the PID, the user and the command. Everything after the container name is passed to ps, so -ef gives a full listing and aux adds CPU and memory columns.

The PIDs shown are the ones on the host, not the numbers the container sees. That is the point: you can use them with host tools like strace -p or look at /proc/PID yourself.

It also works for containers that have no ps binary at all, like many small or distroless images. There docker exec mycontainer ps aux simply fails, while docker top still works because the host does the listing.

The caveat is that the container has to be running, since a stopped container has no processes to show. For overall resource use over time docker stats is the better view, and the Compose version is docker compose top, which lists the processes of the services of a project.

Further reading: docker container top reference

More Docker tips ONBUILD RUN /usr/local/bin/python-build --dir /app/src SHELL ["/bin/bash", "-c"] docker commit <container> myname/testimage:version3 docker import /path/to/exampleimage.tgz docker compose events All Docker tips (192) All topics

Link