Docker Commands Cheat Sheet

Common Docker commands: run, ps, build, compose, exec, logs, volume and more, with notes for everyday container work.

CommandDescription
docker --versionShow the Docker client version
docker versionShow client and server versions
docker infoDisplay system-wide info
docker loginLog in to a registry
docker pullPull an image from a registry
docker pushPush an image to a registry
docker imagesList local images (-a all)
docker rmiRemove an image (-f force)
docker buildBuild from a Dockerfile (-t tag)
docker runRun a container (-d detach / -p port)
docker psList running containers (-a all)
docker stopStop a running container
docker startStart a stopped container
docker restartRestart a container
docker rmRemove a container (-f force / -v volume)
docker execRun a command in a container (-it)
docker logsFetch container logs (-f follow)
docker cpCopy files between container and host
docker inspectReturn low-level JSON info
docker topShow running processes in a container
docker compose upStart compose services (-d)
docker compose downStop and remove compose resources
docker compose buildBuild images in compose
docker network lsList Docker networks
docker volume lsList volumes
docker system pruneRemove unused data (-a all)
docker statsLive 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.