Docker Commands Cheat Sheet
Common Docker commands: run, ps, build, compose, exec, logs, volume and more, with notes for everyday container work.
| Command | Description |
|---|---|
| docker --version | Show the Docker client version |
| docker version | Show client and server versions |
| docker info | Display system-wide info |
| docker login | Log in to a registry |
| docker pull | Pull an image from a registry |
| docker push | Push an image to a registry |
| docker images | List local images (-a all) |
| docker rmi | Remove an image (-f force) |
| docker build | Build from a Dockerfile (-t tag) |
| docker run | Run a container (-d detach / -p port) |
| docker ps | List running containers (-a all) |
| docker stop | Stop a running container |
| docker start | Start a stopped container |
| docker restart | Restart a container |
| docker rm | Remove a container (-f force / -v volume) |
| docker exec | Run a command in a container (-it) |
| docker logs | Fetch container logs (-f follow) |
| docker cp | Copy files between container and host |
| docker inspect | Return low-level JSON info |
| docker top | Show running processes in a container |
| docker compose up | Start compose services (-d) |
| docker compose down | Stop and remove compose resources |
| docker compose build | Build images in compose |
| docker network ls | List Docker networks |
| docker volume ls | List volumes |
| docker system prune | Remove unused data (-a all) |
| docker stats | Live resource usage stats |
Frequently Asked Questions
What is the difference between docker run and docker create?
`docker create` only creates a container without starting it; `docker run` is create + start, launching the main process immediately (in the foreground, or with `-d` detached).
How do I enter a running container?
Use `docker exec -it <container> /bin/sh` (or `/bin/bash`) for an interactive shell; add `--rm` to auto-clean the exec process on exit.
How do I see disk space used by containers?
`docker system df` shows overall image/container/volume usage; `docker ps -s` shows each container's writable size; clean up with `docker system prune -a`.
How do I save a container's changes as a new image?
Use `docker commit <container> <new-image>` to freeze the current state, but writing a Dockerfile is preferred for reproducible, versioned builds.