Ultimate Docker Cheat Sheet
Here’s a Docker Cheat Sheet with all the essential commands and their explanations:
Docker Basics
docker --versionCheck the installed Docker versiondocker infoDisplay system-wide information about Dockerdocker helpGet help on Docker commands
Docker Images
docker imagesList all locally available Docker imagesdocker pull <image>Download an image from Docker Hubdocker build -t <image_name> .Build a Docker image from a Dockerfile in the current directorydocker tag <image_id> <repo_name>:<tag>Add a tag to an imagedocker rmi <image_id>Remove an image
Docker Containers
docker psList running containersdocker ps -aList all containers (including stopped ones)docker run -d <image>Run a container in detached mode (background)docker run -it <image> /bin/bashRun a container interactively with a Bash shelldocker run --name <name> -p 8080:80 <image>Run a container with a specific name and port mappingdocker stop <container_id>Stop a running containerdocker start <container_id>Start a stopped containerdocker restart <container_id>Restart a containerdocker rm <container_id>Remove a stopped containerdocker logs <container_id>View logs of a containerdocker exec -it <container_id> /bin/bashAccess a running container’s shell
Docker Networks
docker network lsList all networksdocker network create <network_name>Create a new networkdocker network rm <network_name>Remove a networkdocker network inspect <network_name>View network detailsdocker network connect <network> <container>Connect a container to a networkdocker network disconnect <network> <container>Disconnect a container from a network
Docker Volumes (Data Persistence)
docker volume lsList all volumesdocker volume create <volume_name>Create a volumedocker volume inspect <volume_name>Get volume detailsdocker volume rm <volume_name>Remove a volumedocker run -v <volume_name>:/data <image>Mount a volume to a container
Get Mahfuzur Rahman’s stories in your inbox
Join Medium for free to get updates from this writer.
Docker Compose
docker-compose upStart containers defined indocker-compose.ymldocker-compose up -dStart in detached mode (background)docker-compose downStop and remove containers, networks, and volumesdocker-compose psList running servicesdocker-compose logsView logs of servicesdocker-compose buildBuild services indocker-compose.yml
Dockerfile Commands
FROM <image>Specifies the base imageRUN <command>Runs a command in the container during the buildCOPY <src> <dest>Copies files from local to containerADD <src> <dest>Copies files and extracts archivesCMD ["executable", "arg1", "arg2"]Default command to run in a containerENTRYPOINT ["executable", "arg1"]Default executable for a containerEXPOSE <port>Opens a port for external accessWORKDIR <path>Sets the working directoryENV <key>=<value>Sets environment variablesVOLUME ["/data"]Creates a mount point for persistence
Docker Container Management
docker top <container>Display running processes inside a containerdocker stats <container>Display real-time resource usage of a containerdocker inspect <container>Get detailed information about a container
Docker Cleanup
docker system pruneRemove all stopped containers, unused networks, and dangling imagesdocker container pruneRemove all stopped containersdocker image pruneRemove unused imagesdocker volume pruneRemove unused volumesdocker network pruneRemove unused networks
Docker Registry & Pushing Images
docker loginLog into Docker Hubdocker tag <image_id> <username>/<repo>:<tag>Tag an image for Docker Hubdocker push <username>/<repo>:<tag>Push an image to Docker Hubdocker pull <username>/<repo>:<tag>Pull an image from the Docker Hub
Docker Security & User Management
docker run --user <uid>:<gid> <image>Run a container as a specific userdocker run --read-only <image>Run a container with a read-only filesystemdocker scan <image>Scan an image for vulnerabilities
Docker Swarm (Orchestration)
docker swarm initInitialize a Docker Swarmdocker swarm join --token <token> <manager_ip>:<port>Join a node to a swarmdocker service create --name <service_name> <image>Deploy a service in Swarmdocker service lsList running servicesdocker service rm <service_name>Remove a service









