Home Topics Tools Cheat Sheets Data Bookmarks

Docker Cheat Sheet

The essential Docker commands, from building images to orchestrating with Compose.

Images

docker build -t name:tag .Build an image from a Dockerfile in the current directory
docker imagesList all local images
docker pull image:tagPull an image from a registry
docker push image:tagPush an image to a registry
docker rmi imageRemove a local image
docker tag source target:tagTag an image with a new name
docker image pruneRemove dangling (untagged) images
docker image prune -aRemove all unused images, not just dangling ones
docker history imageShow the layer history of an image
docker inspect imageDisplay detailed image metadata as JSON

Containers

docker run imageCreate and start a container from an image
docker run -d imageRun a container in detached (background) mode
docker run -it image shRun interactively with a shell
docker run --name name imageRun a container with a custom name
docker run -p host:container imageMap a host port to a container port
docker run -v host:container imageBind-mount a host directory into the container
docker run --rm imageAutomatically remove the container when it exits
docker run -e KEY=VAL imageSet an environment variable
docker psList running containers
docker ps -aList all containers including stopped
docker stop containerGracefully stop a running container
docker kill containerForce-stop a container immediately
docker start containerStart a stopped container
docker restart containerRestart a container
docker rm containerRemove a stopped container
docker rm -f containerForce-remove a container, even if running
docker container pruneRemove all stopped containers

Exec & Logs

docker exec -it container shOpen an interactive shell inside a running container
docker exec container commandRun a one-off command in a running container
docker logs containerView container logs
docker logs -f containerFollow (tail) container logs in real time
docker logs --tail n containerShow only the last n lines of logs
docker logs --since time containerShow logs since a timestamp or duration (e.g. 10m)
docker top containerDisplay running processes inside a container
docker statsLive stream of resource usage for all running containers
docker inspect containerDetailed container metadata as JSON
docker cp container:path localCopy files from a container to the host
docker cp local container:pathCopy files from the host into a container

Volumes

docker volume create nameCreate a named volume
docker volume lsList all volumes
docker volume inspect nameShow volume details
docker volume rm nameRemove a volume
docker volume pruneRemove all unused volumes
docker run -v vol:path imageMount a named volume into a container
docker run --mount type=bind,src=host,dst=container imageBind mount using the --mount syntax (more explicit)

Networks

docker network create nameCreate a user-defined bridge network
docker network lsList all networks
docker network inspect nameShow network details and connected containers
docker network connect net containerAttach a running container to a network
docker network disconnect net containerDetach a container from a network
docker network rm nameRemove a network
docker network pruneRemove all unused networks
docker run --network name imageRun a container on a specific network

Compose

docker compose upCreate and start all services defined in compose.yaml
docker compose up -dStart services in detached mode
docker compose up --buildRebuild images before starting services
docker compose downStop and remove containers, networks
docker compose down -vAlso remove named volumes declared in the file
docker compose psList containers managed by Compose
docker compose logs -fFollow logs from all services
docker compose logs serviceView logs for a specific service
docker compose exec service shOpen a shell in a running service container
docker compose run service cmdRun a one-off command against a service
docker compose pullPull the latest images for all services
docker compose buildBuild or rebuild all service images
docker compose configValidate and display the resolved compose file

System & Cleanup

docker system dfShow disk usage by images, containers, and volumes
docker system pruneRemove stopped containers, unused networks, dangling images
docker system prune -a --volumesNuclear option — remove everything unused including volumes
docker infoDisplay system-wide Docker information
docker versionShow Docker client and server versions

Dockerfile Reference

FROM image:tagBase image for the build
WORKDIR /appSet the working directory for subsequent instructions
COPY src destCopy files from host into the image
RUN commandExecute a command during the build (creates a new layer)
ENV KEY=VALSet an environment variable
ARG name=defaultDefine a build-time variable
EXPOSE portDocument which port the container listens on
VOLUME /dataCreate a mount point for a volume
CMD ["exec", "arg"]Default command when the container starts (overridable)
ENTRYPOINT ["exec"]Main executable — CMD becomes default arguments
HEALTHCHECK CMD commandDefine a command to check if the container is healthy
USER nameSwitch to a non-root user for subsequent instructions
.dockerignoreFile listing patterns to exclude from the build context

No commands match your search.

Docker Cheat Sheet