Skip to content

15 Actually Useful Docker Commands (2026)

DodaTech Updated 2026-06-20 4 min read

In this tutorial, you'll learn about 15 actually useful docker commands (2026). We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.

docker run, docker ps, docker stop — you use these daily. The commands here solve the problems that come after: disks filling up with orphaned layers, containers that won't start and you don't know why, copying files in and out of running containers, and debugging why a container exited. These are the commands you reach for when something goes wrong.

Inspection & Debugging

docker inspect — Returns detailed JSON metadata about any container, image, volume, or network. Use --format to extract specific values without Parsing the full JSON.

docker inspect --format '{{.State.Running}}' container_name
docker inspect --format '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name

docker logs — Shows container stdout/stderr. -f follows, --tail 100 shows last 100 lines, --since 5m shows recent entries.

docker logs -f --tail 100 container_name

docker stats — Live CPU, memory, network, and disk I/O for all running containers. Like htop for containers.

docker stats --no-stream  # One-shot, no continuous scrolling

docker top — Lists processes running inside a container. Useful when a container is misbehaving and you need to see what's executing.

docker top container_name

docker diff — Shows filesystem changes (added, modified, deleted) in a container compared to its base image. Essential for understanding what a container actually changed at runtime.

docker diff container_name
# Output: C /app/config.json, A /app/tmp/data.json

docker events — Streams Docker daemon events in real-time — container starts, stops, image pulls, volume mounts, etc.

docker events --filter 'event=start'  # Watch for new containers

docker port — Lists port mappings for a running container. Faster than Parsing docker ps or docker inspect.

docker port container_name
# 3000/tcp -> 0.0.0.0:3000

docker history — Shows every layer in an image with its size and creation command. The primary tool for understanding why an image is large.

docker history image_name --no-trunc

Cleanup & Disk Management

docker system df — Shows total Docker disk usage by type: images, containers, volumes, and build cache. Run this first when you suspect disk pressure.

docker system df
# TYPE            TOTAL     ACTIVE    SIZE    RECLAIMABLE
# Images          12        5         3.2GB   1.1GB (34%)

docker system prune — Removes all unused containers, networks, dangling images, and build cache. docker system prune -a --volumes is the nuclear option — reclaims everything Docker isn't actively using.

docker system prune -af  # Remove all unused, no prompt

docker container prune — Removes all stopped containers. Safer than system prune when you only want to target containers.

docker container prune -f

docker image prune — Removes dangling images (tagged <none>). -a removes all unused images, not just dangling ones.

docker image prune -a

docker Builder prune — Clears the build cache. The build cache can grow to multiple GB over time, especially with CI/CD pipelines. Run this weekly on dev machines.

docker <a href="/design-patterns/builder/">Builder</a> prune -af

Utility

docker cp — Copies files between a container and the host filesystem. Works both ways. No need to mount volumes for one-off file transfers.

docker cp container_name:/app/logs/app.log ./app.log
docker cp ./config.json container_name:/app/config.json

docker commit — Creates a new image from a container's current state. Useful for saving changes made during debugging, but prefer Dockerfiles for reproducible builds.

docker commit container_name my-image:tag

Compose & Context

Docker Compose logs --tail --follow — Streams logs from all services in a compose file. Ctrl+C exits without stopping services.

docker compose logs -f --tail 50

Docker Compose exec — Runs a command in a running service container. Unlike <a href="/devops/docker-compose/">Docker Compose</a> run, this connects to an already-running container.

docker compose exec web bash
docker compose exec db pg_dump -U user mydb > backup.sql

docker context — Switches between Docker endpoints (local, remote, cloud). Essential for teams managing multiple Docker environments.

docker context create remote --docker "host=ssh://user@server"
docker context use remote
Is docker system prune -a --volumes safe?

It's safe for data stored only in containers — but it permanently removes all unused volumes. If a volume contains database data or configuration you haven't backed up, it's gone. Always verify which volumes are unused before running with --volumes.

What is the difference between docker-compose exec and docker-compose run?

exec runs a command in an already-running container. run starts a new container from a service definition. Use exec for interactive debugging, run for one-off tasks like migrations.

How do I monitor Docker disk usage without command flags?

docker system df --verbose shows per-resource breakdown including which images and containers consume the most space. Pipe to grep or sort for specific queries.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro