Docker Commands

Docker commands cheatsheet.

Build images, run containers, and use Compose — the Docker commands you actually need. Tap to copy.

Images
docker pull <image>Download an image from a registry
docker build -t <name> .Build an image from the Dockerfile here
docker imagesList local images
docker rmi <image>Remove an image
Containers
docker run <image>Create and start a container from an image
docker run -d -p 8080:80 <image>Run detached and map a port
docker psList running containers
docker ps -aList all containers, including stopped
docker stop <id>Stop a running container
docker rm <id>Remove a stopped container
docker exec -it <id> bashOpen an interactive shell in a container
docker logs -f <id>Stream a container's logs
Compose
docker compose upStart the services in docker-compose.yml
docker compose up -dStart services in the background
docker compose downStop and remove the compose services
docker compose buildBuild or rebuild compose services
docker compose logs -fFollow logs for all services
Cleanup
docker system pruneRemove unused containers, networks and images
docker volume lsList volumes
docker network lsList networks

Containers without the guesswork

The core Docker loop is build an image, run a container, and ps to see what's running. Add docker exec -it <id> bash to get a shell inside a container and docker compose up -d to bring up a whole stack, and you've covered most day-to-day Docker.

FAQ

How do I get a shell inside a running container?
Run docker exec -it bash (or sh if bash isn't available) to open an interactive shell.
How do I free up disk space used by Docker?
Run docker system prune to remove unused containers, networks and dangling images. Add -a to also remove unused images.

More cheatsheets