Skip to main content

Command Palette

Search for a command to run...

Docker Cheat Sheet ๐Ÿณ

Day20

Published
โ€ข3 min readโ€ขView as Markdown

Docker Basic Commands ๐Ÿš€

CommandDescription
docker versionDisplay Docker version information
docker infoDisplay system-wide Docker info
docker pull <image>Download an image from Docker Hub
docker imagesList all local images
docker psList running containers
docker ps -aList all containers (including stopped)
docker run <image>Create and start a container
docker start <container>Start a stopped container
docker stop <container>Stop a running container
docker restart <container>Restart a running container
docker exec -it <cont> <cmd>Run command in a running container
docker rm <container>Remove a stopped container
docker rmi <image>Remove an image
docker logs <container>View logs from a container
docker build -t <name> <path>Build an image from a Dockerfile

Dockerfile Commands ๐Ÿ—๏ธ

CommandDescription
FROMSet base image for subsequent commands
RUNExecute command during image build
COPY or ADDCopy files from host into the image
WORKDIRSet working directory
ENVSet environment variables
EXPOSEDeclare open ports at runtime
CMDSpecify default container command
ENTRYPOINTConfigure entry point for the container
VOLUMECreate mount point for external volumes
USERSet user for subsequent commands
LABELAdd metadata to the image

Docker Compose Commands ๐Ÿ› ๏ธ

CommandDescription
docker-compose upCreate and start containers
docker-compose downStop and remove containers
docker-compose buildBuild or rebuild services
docker-compose psList running containers
docker-compose logsView output logs from containers
docker-compose exec <svc> <cmd>Run cmd in a running container
docker-compose stopStop services
docker-compose startStart services

Docker Volumes Commands ๐Ÿ“ฆ

CommandDescription
docker volume create <name>Create a named volume
docker volume lsList all volumes
docker volume inspect <name>Display detailed volume info
docker volume ls -qList only volume names/IDs
docker volume pruneRemove all unused volumes
docker volume rm <name>Remove a specific volume
docker volume create --driver <name>Create a volume with driver
docker run -v <vol>:<cont_path> <img>Mount volume in container
docker run -v <host>:<cont_path> <img>Mount host dir in container
docker run -v <vol>:/data <img>Mount volume at /data in container
docker run --mount src=<vol>,target=<cont_path> <img>Alt. syntax
docker volume create --label <k>=<v> <name>Create labeled volume
docker volume prune --filter "label=<k>=<v>"Prune volumes based on label

Docker Networking Commands ๐ŸŒ

CommandDescription
docker network create <name>Create a custom network
docker network lsList all networks
docker network inspect <name>Display detailed network info
docker network connect <net> <cont>Connect container to network
docker network disconnect <net> <cont>Disconnect container

Do check out the following blogs to understand the commands more:

  1. Docker for DevOps Engineers

  2. Docker Project for DevOps Engineers

  3. Mastering Docker Compose: Building Beautiful Two-Tier Projects and Beyond

  4. Deep Dive into Docker: Unveiling Containerization, Networking, and Volumes

90daysofdevops

Part 14 of 22

90 Days of DevOps Discourse: Unveiling the Path to Efficiency and Excellence!

Up next

Docker Important interview Questions

Day21