Sitemap
Mahfuzur Rahman

Mahfuzur Rahman

Software Developer, Expertise in PHP, Laravel, JS, Vue, Nuxt, System Design, Database Design, DSA. Love learning and exploring new tech everyday.

Ultimate Docker Cheat Sheet

3 min readFeb 2, 2025

--

Press enter or click to view image in full size

Here’s a Docker Cheat Sheet with all the essential commands and their explanations:

Docker Basics

  1. docker --version Check the installed Docker version
  2. docker infoDisplay system-wide information about Docker
  3. docker helpGet help on Docker commands

Docker Images

  1. docker imagesList all locally available Docker images
  2. docker pull <image>Download an image from Docker Hub
  3. docker build -t <image_name> .Build a Docker image from a Dockerfile in the current directory
  4. docker tag <image_id> <repo_name>:<tag>Add a tag to an image
  5. docker rmi <image_id>Remove an image

Docker Containers

  1. docker psList running containers
  2. docker ps -aList all containers (including stopped ones)
  3. docker run -d <image>Run a container in detached mode (background)
  4. docker run -it <image> /bin/bashRun a container interactively with a Bash shell
  5. docker run --name <name> -p 8080:80 <image>Run a container with a specific name and port mapping
  6. docker stop <container_id>Stop a running container
  7. docker start <container_id>Start a stopped container
  8. docker restart <container_id>Restart a container
  9. docker rm <container_id>Remove a stopped container
  10. docker logs <container_id>View logs of a container
  11. docker exec -it <container_id> /bin/bashAccess a running container’s shell

Docker Networks

  1. docker network lsList all networks
  2. docker network create <network_name>Create a new network
  3. docker network rm <network_name>Remove a network
  4. docker network inspect <network_name>View network details
  5. docker network connect <network> <container>Connect a container to a network
  6. docker network disconnect <network> <container>Disconnect a container from a network

Docker Volumes (Data Persistence)

  1. docker volume lsList all volumes
  2. docker volume create <volume_name>Create a volume
  3. docker volume inspect <volume_name>Get volume details
  4. docker volume rm <volume_name>Remove a volume
  5. docker 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

  1. docker-compose upStart containers defined in docker-compose.yml
  2. docker-compose up -dStart in detached mode (background)
  3. docker-compose downStop and remove containers, networks, and volumes
  4. docker-compose psList running services
  5. docker-compose logsView logs of services
  6. docker-compose buildBuild services in docker-compose.yml

Dockerfile Commands

  1. FROM <image>Specifies the base image
  2. RUN <command>Runs a command in the container during the build
  3. COPY <src> <dest>Copies files from local to container
  4. ADD <src> <dest>Copies files and extracts archives
  5. CMD ["executable", "arg1", "arg2"]Default command to run in a container
  6. ENTRYPOINT ["executable", "arg1"]Default executable for a container
  7. EXPOSE <port>Opens a port for external access
  8. WORKDIR <path>Sets the working directory
  9. ENV <key>=<value>Sets environment variables
  10. VOLUME ["/data"]Creates a mount point for persistence

Docker Container Management

  1. docker top <container>Display running processes inside a container
  2. docker stats <container>Display real-time resource usage of a container
  3. docker inspect <container>Get detailed information about a container

Docker Cleanup

  1. docker system pruneRemove all stopped containers, unused networks, and dangling images
  2. docker container pruneRemove all stopped containers
  3. docker image pruneRemove unused images
  4. docker volume pruneRemove unused volumes
  5. docker network pruneRemove unused networks

Docker Registry & Pushing Images

  1. docker loginLog in to Docker Hub
  2. docker tag <image_id> <username>/<repo>:<tag>Tag an image for Docker Hub
  3. docker push <username>/<repo>:<tag>Push an image to Docker Hub
  4. docker pull <username>/<repo>:<tag>Pull an image from the Docker Hub

Docker Security & User Management

  1. docker run --user <uid>:<gid> <image>Run a container as a specific user
  2. docker run --read-only <image>Run a container with a read-only filesystem
  3. docker scan <image>Scan an image for vulnerabilities

Docker Swarm (Orchestration)

  1. docker swarm initInitialize a Docker Swarm
  2. docker swarm join --token <token> <manager_ip>:<port>Join a node to a swarm
  3. docker service create --name <service_name> <image>Deploy a service in Swarm
  4. docker service lsList running services
  5. docker service rm <service_name>Remove a service

--

--

Mahfuzur Rahman
Mahfuzur Rahman

Written by Mahfuzur Rahman

Software Developer, Expertise in PHP, Laravel, JS, Vue, Nuxt, System Design, Database Design, DSA. Love learning and exploring new tech everyday.