DropVPS Team
Writer: Cooper Reagan
How to install htop in docker?

Table of Contents
Start with a basic Dockerfile. You’ll need to choose a base image. For example, let’s say you’re using Debian or Ubuntu as the base:
FROM debian:bullseye
RUN apt-get update && \
apt-get install -y htop && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
Build your image with:
docker build -t htop-container .
And run it:
docker run -it --rm htop-container htop
That works fine if your container has a full init and a working terminal interface. But if you’re adding htop to an existing container, follow this method:
Step into the container
docker exec -it container_name_or_id bash
Once inside:
apt update
apt install htop
Then run:
htop
If your base image is Alpine, you’ll need to use apk instead:
FROM alpine:latest
RUN apk update && \
apk add htop
To enter an Alpine-based container and install manually:
docker exec -it container_name_or_id sh
apk add htop
htop
Sometimes, the container doesn’t have bash or sh depending on the base image. In that case, try replacing bash with sh, or use docker attach as a fallback.
You can also run htop without modifying the container image by mounting htop from the host:
docker run -it --rm --pid=host debian bash -c "apt update && apt install -y htop && htop"
The --pid=host flag allows htop to see host processes — useful for debugging or system monitoring from inside a container.
Want a cleaner and more reusable setup? Create a dedicated docker-compose.yml:
version: '3.8'
services:
htop:
image: debian
entrypoint: ["bash", "-c", "apt update && apt install -y htop && htop"]
pid: "host"
tty: true
Then just run:
docker-compose up
Done. You’ve got htop running inside Docker with full flexibility. Whether you’re debugging, monitoring, or just experimenting, this setup gets you what you need fast — no bloated images, no guesswork.