Skip to main content

Docker Cheatsheet

By Dejan Panovski Updated on Download PDF

Quick reference for Docker commands and concepts

Docker is a platform for building, shipping, and running applications in containers. This cheatsheet covers essential Docker commands for managing containers, images, volumes, networks, and Docker Compose. A handy quick reference for daily Docker workflows.

Container Lifecycle

Create, start, stop, and remove containers.

CommandDescription
docker run imageCreate and start a container
docker run -d imageRun container in background
docker run -it image shRun with interactive shell
docker run --name myapp imageRun with a custom name
docker run -p 8080:80 imageMap host port to container port
docker run -v /host:/container imageMount a volume
docker start containerStart a stopped container
docker stop containerGracefully stop a container
docker restart containerRestart a container
docker rm containerRemove a stopped container
docker rm -f containerForce remove a running container
docker kill containerKill a container (SIGKILL)
docker pause containerPause a running container
docker unpause containerUnpause a container

Container Inspection

Monitor and inspect running containers.

CommandDescription
docker psList running containers
docker ps -aList all containers
docker logs containerView container logs
docker logs -f containerFollow log output
docker inspect containerDetailed container info (JSON)
docker top containerList running processes
docker statsLive resource usage for all containers
docker stats containerLive resource usage for one container
docker port containerShow port mappings
docker diff containerShow filesystem changes

Images

Pull, build, and manage Docker images.

CommandDescription
docker pull image:tagPull image from registry
docker push image:tagPush image to registry
docker build -t name .Build image from Dockerfile
docker build -f Dockerfile.dev .Build with custom Dockerfile
docker imagesList local images
docker rmi imageRemove an image
docker tag source target:tagTag an image
docker save image > file.tarSave image to tar archive
docker load < file.tarLoad image from tar archive
docker history imageShow image layer history

Dockerfile Instructions

Key instructions for writing Dockerfiles.

InstructionDescription
FROM image:tagBase image
RUN commandExecute command during build
CMD ["executable"]Default command at runtime
ENTRYPOINT ["executable"]Fixed command at runtime
COPY src destCopy files from host
ADD src destCopy files (supports URLs, tar)
WORKDIR /pathSet working directory
EXPOSE 80Document container port
ENV KEY=valueSet environment variable
ARG KEY=valueBuild-time variable
VOLUME ["/data"]Create mount point
USER usernameSet runtime user

Volumes

Manage persistent data with volumes.

CommandDescription
docker volume create volCreate a named volume
docker volume lsList volumes
docker volume inspect volVolume details
docker volume rm volRemove a volume
docker volume pruneRemove unused volumes
docker run -v vol:/data imageMount named volume
docker run -v /host:/data imageBind mount host directory
docker run --tmpfs /tmp imageMount tmpfs (in-memory)

Networks

Create and manage container networks.

CommandDescription
docker network create netCreate a network
docker network lsList networks
docker network inspect netNetwork details
docker network rm netRemove a network
docker network connect net containerConnect container to network
docker network disconnect net containerDisconnect from network
docker run --network net imageRun container on network

Docker Compose

Manage multi-container apps with Docker Compose .

CommandDescription
docker compose upCreate and start services
docker compose up -dStart in background
docker compose downStop and remove services
docker compose down -vAlso remove volumes
docker compose buildBuild service images
docker compose psList running services
docker compose logsView service logs
docker compose logs -f serviceFollow logs for a service
docker compose exec service shShell into running service
docker compose pullPull service images
docker compose restartRestart all services

System & Cleanup

Monitor disk usage and clean up resources.

CommandDescription
docker system dfShow Docker disk usage
docker system pruneRemove unused data
docker system prune -aRemove all unused data
docker image pruneRemove dangling images
docker image prune -aRemove all unused images
docker container pruneRemove stopped containers
docker volume pruneRemove unused volumes
docker network pruneRemove unused networks

Exec & Copy

Run commands in containers and copy files.

CommandDescription
docker exec -it container shOpen shell in container
docker exec container commandRun command in container
docker exec -u root container cmdRun as specific user
docker cp container:/path ./localCopy from container
docker cp ./local container:/pathCopy to container
docker attach containerAttach to running container
docker wait containerWait for container to stop

Registry & Login

Authenticate and interact with registries.

CommandDescription
docker loginLog in to Docker Hub
docker login registry.example.comLog in to private registry
docker logoutLog out from registry
docker search termSearch Docker Hub
docker push user/image:tagPush image to registry
docker pull user/image:tagPull image from registry