Skip to main content

Command Palette

Search for a command to run...

Docker Cheat Sheet 🐳

Published
Docker Cheat Sheet 🐳
R

I'm Rudraksh Laddha — a DevOps engineer and emerging full-stack developer, passionate about building scalable, reliable systems that solve real-world problems.

With a solid foundation in cloud infrastructure automation using tools like Kubernetes, Docker, Terraform, and AWS, I thrive in environments where efficiency, resilience, and automation are key.

But my journey doesn't stop at infrastructure. I'm actively expanding into full-stack development, building dynamic applications using React, Node.js, and MongoDB. Whether it's designing cloud-native CI/CD pipelines or developing intuitive user interfaces, I enjoy creating end-to-end solutions — from server to screen.

Right now, I'm: 🧩 Building full-stack applications that merge DevOps reliability with engaging frontend experiences 🛠️ Contributing to open-source projects, learning through collaboration and real-world scenarios 🚀 Growing Virendana Ui, my own UI library focused on expressive, clean design systems 🚀 Growing Learn Virendana, where I share my personalized learning journey — from beginner to experienced 🎮 Developing side projects like 2048 Rush, blending product thinking with scalable infrastructure My long-term goal? To bridge DevOps and development — building products that are not just functional and fast, but also resilient, beautiful, and ready for scale.

🔹 Docker Basics

CommandDescription
docker --versionCheck Docker version
docker infoDisplay system-wide information
docker helpShow help for Docker commands

🔹 Working with Containers

CommandDescription
docker run <image>Run a container from an image
docker run -d <image>Run a container in detached mode (background)
docker run -it <image> bashRun a container interactively with a shell
docker psList running containers
docker ps -aList all containers (including stopped ones)
docker start <container>Start a stopped container
docker stop <container>Stop a running container
docker restart <container>Restart a container
docker kill <container>Kill a running container immediately
docker rm <container>Remove a stopped container
docker rm -f <container>Force remove a running container
docker logs <container>Show logs of a container
docker exec -it <container> bashAccess a running container's shell
docker inspect <container>Get detailed information about a container
docker statsShow resource usage of running containers
docker rename <old> <new>Rename a container
docker pause <container>Pause a running container
docker unpause <container>Unpause a paused container

🔹 Working with Images

CommandDescription
docker imagesList all local images
docker pull <image>Download an image from Docker Hub
docker push <image>Upload an image to Docker Hub
docker rmi <image>Remove an image
docker tag <image> <new_image>Rename/tag an image
docker history <image>Show history of an image
docker save -o image.tar <image>Save an image to a tar file
docker load -i image.tarLoad an image from a tar file
docker commit <container> <new_image>Create an image from a container

🔹 Docker Volumes (Storage Management)

CommandDescription
docker volume create <volume>Create a new volume
docker volume lsList all volumes
docker volume inspect <volume>Get details of a volume
docker volume rm <volume>Remove a volume
docker run -v <volume>:/path <image>Mount a volume inside a container

🔹 Docker Networks

CommandDescription
docker network lsList all networks
docker network create <network>Create a new network
docker network inspect <network>Get details of a network
docker network connect <network> <container>Connect a container to a network
docker network disconnect <network> <container>Disconnect a container from a network
docker network rm <network>Remove a network

🔹 Building Custom Images (Dockerfile)

CommandDescription
docker build -t <image_name> .Build an image from a Dockerfile in the current directory
docker build -t <image_name> -f <Dockerfile>Build an image using a specific Dockerfile
docker run --rm <image>Run a container and remove it after exiting

Basic Dockerfile Example:

# Use an official image as a base
FROM node:16

# Set the working directory
WORKDIR /app

# Copy files and install dependencies
COPY package.json .
RUN npm install

# Copy the rest of the app
COPY . .

# Expose a port and run the app
EXPOSE 3000
CMD ["node", "server.js"]

🔹 Docker Compose

CommandDescription
docker-compose upStart services in the docker-compose.yml file
docker-compose up -dStart services in detached mode
docker-compose downStop and remove all containers from docker-compose.yml
docker-compose psList running services
docker-compose restartRestart all services
docker-compose logsView logs of all services
docker-compose exec <service> bashOpen a shell inside a service container

Basic docker-compose.yml Example:

version: '3'
services:
  web:
    image: nginx
    ports:
      - "8080:80"
    volumes:
      - ./html:/usr/share/nginx/html
  db:
    image: mysql
    environment:
      MYSQL_ROOT_PASSWORD: secret

🔹 Managing Docker System Resources

CommandDescription
docker system dfShow Docker disk usage
docker system pruneRemove unused data (stopped containers, networks, images)
docker container pruneRemove all stopped containers
docker image pruneRemove unused images
docker volume pruneRemove unused volumes
docker network pruneRemove unused networks

🔹 Security & User Management

CommandDescription
docker loginLog in to Docker Hub
docker logoutLog out from Docker Hub
docker secret create <name> <file>Create a secret from a file
docker secret lsList all secrets
docker secret rm <name>Remove a secret

🔹 Docker Swarm (Orchestration)

CommandDescription
docker swarm initInitialize a Swarm cluster
docker swarm join --token <token> <manager-IP>Join a Swarm cluster
docker swarm leaveLeave a Swarm cluster
docker service create --name web -p 80:80 nginxCreate a service in Swarm
docker service lsList all services
docker service rm <service>Remove a service
docker node lsList all nodes in the Swarm

🔹 Kubernetes with Docker

CommandDescription
kubectl get podsList all running pods
kubectl get servicesList all services
kubectl logs <pod>View logs of a pod
kubectl exec -it <pod> -- bashAccess a pod’s shell
kubectl apply -f <file>.yamlApply a Kubernetes configuration

Linux Cheatsheet