15 Actually Useful Docker Commands (2026)
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_namedocker logs — Shows container stdout/stderr. -f follows, --tail 100 shows last 100 lines, --since 5m shows recent entries.
docker logs -f --tail 100 container_namedocker 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 scrollingdocker top — Lists processes running inside a container. Useful when a container is misbehaving and you need to see what’s executing.
docker top container_namedocker 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.jsondocker events — Streams Docker daemon events in real-time — container starts, stops, image pulls, volume mounts, etc.
docker events --filter 'event=start' # Watch for new containersdocker 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:3000docker 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-truncCleanup & 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 promptdocker container prune — Removes all stopped containers. Safer than system prune when you only want to target containers.
docker container prune -fdocker image prune — Removes dangling images (tagged <none>). -a removes all unused images, not just dangling ones.
docker image prune -adocker 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 builder prune -afUtility
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.jsondocker 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:tagCompose & 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 50docker compose exec — Runs a command in a running service container. Unlike docker compose run, this connects to an already-running container.
docker compose exec web bash
docker compose exec db pg_dump -U user mydb > backup.sqldocker 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 remoteBuilt by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro