Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • HTML Cheat Sheet
  • CSS Cheat Sheet
  • JS Cheat Sheet
  • Bootstrap Cheat Sheet
  • jQuery Cheat Sheet
  • Angular Cheat Sheet
  • SDE Sheet
  • Facebook SDE Sheet
  • Amazon SDE Sheet
  • Apple SDE Sheet
  • Netflix SDE Sheet
  • Google SDE Sheet
  • Wipro SDE Sheet
  • Infosys SDE Sheet
  • TCS SDE Sheet
  • Cognizant SDE Sheet
  • HCL SDE Sheet
  • Mass Recruiters Sheet
  • Product-Based Coding Sheet
  • Company-Wise Practice Sheet
  • Love Babbar Sheet
Open In App
Next Article:
C++ Cheatsheet
Next article icon

Docker Cheat Sheet : Complete Guide (2024)

Last Updated : 04 Jan, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Docker is a very popular tool introduced to make it easier for developers to create, deploy, and run applications using containers. A container is a utility provided by Docker to package and run an application in a loosely isolated environment. Containers are lightweight and contain everything needed to run an application, such as libraries and other dependencies packed by the developer during the application's packaging process. This assures developers that their application can be run on any other machine. Here, we're going to provide you with an ultimate Docker Cheat Sheet that will help you to learn Docker Commands easily.

This Docker command cheatsheet is a summary of commonly used Docker commands and their options, as well as other useful information related to Docker. It covers all the important commands required for Docker operations, including Docker installation, building, running, shipping, and cleaning up, as well as interaction with containers. This cheat sheet will be a handy reference for you to perform various tasks with Docker, such as installing, building, running, shipping, and cleaning up containers. This Docker cheat sheet is useful for both - DevOps freshers who're learning Docker and experienced Docker users who need to recall a specific command or option but may not remember all the details.

Docker-Cheatsheet.webp

What is Docker?

Docker allows you to collect and run an application in a container, which is a loosely isolated environment. Because of the isolation and security, you can run multiple containers on a single host at the same time. Containers are lightweight and include everything required to run the application, eliminating the need to rely on what is already installed on the host. You may easily share containers while working, and you can ensure that everyone with whom you share gets the same container that functions in the same way.

Pre-requisite: Docker, DockerHub

The below Docker cheat sheet contains commands to manage the docker containers, images, network, volumes, building running, and deploying containers and also covered commands related to Docker Compose.

Docker Cheat Sheet - Table of Content

Table of Content

  • Installation Commands
  • Docker Login Commands
  • Image Management Commands
  • Image Transfer Commands
  • Docker Hub Commands
  • General Docker Commands
  • Containers Management Commands
  • Docker Image Management Commands
  • Docker Network Commands
  • Docker Exposing Ports Commands
  • Docker Commands Removing Containers, Images, Volumes, And Networks
  • Docker Swarm Commands
  • Docker file Commands
  • Docker Volume Commands
  • Docker CP commands
  • Docker Security Commands (Docker Scout)

Docker Commands Cheat Sheet

The Docker cheat sheet will help you as a reference guide from where you can quickly read of mostly used common commands of Docker. The cheat sheet will help as a handy guide for developers and other system administrations who are working with Docker. Let's get started:

Installation Commands

Name

Command

Installation on Linux

curl -sSL https://gcurl -fsSL https://get.docker.com -o get-docker.sh && sudo sh get-docker.sh

Docker Login Commands

Name

Command

Log in to a Registry

docker login

Logout from a Registry

docker logout

Image Management Commands

Docker images are self-contained software packages that contain all the necessary components to run an application. These components include the code, runtime, system tools, system libraries, and settings. Docker images are lightweight and easy to use.

Name

Command

Build an image

docker build -t <image_name>

Pulling an Image

docker image pull nginx

Pulling an Image Example

docker image pull <Name of The Image>:<Tag>

Image Transfer Commands

Name

Command

Pushing an Image

docker image push <usernameofregistry:Imagename: tag>

Pushing an Image Example

docker image push eon01/nginx localhost:5000/myadmin/nginx

Docker Hub Commands

Docker Hub is a service provided by Docker for finding and sharing container images with your team. Learn more and find images at "https://hub.docker.com".

Name

Command

Login into Docker

-docker login -u <username>

Publish an image to Docker Hub

-docker push <username>/<image_name>

Search Hub for an image

-docker search <image_name>

Pull an image from a Docker Hub

-docker pull <image_name>

General Docker Commands

Name

Command

Start the docker daemon

docker -d

Get help with Docker. Can also use –help on all subcommands

docker --help

Display system-wide information

docker info

Containers Management Commands

CONTAINERS

A docker image's runtime instance is referred to as a container. The container remains consistent regardless of the infrastructure in use. This isolation of software from its environment guarantees uniformity in function, even in cases where there are discrepancies between development and staging.

Name

Command

Starting Containers

docker container start nginx

Stopping Containers

docker container stop nginx

Restarting Containers

docker container restart nginx

Pausing Containers

docker container pause nginx

Unpausing Containers

docker container unpause nginx

Blocking a Container

docker container wait nginx

Sending SIGKILL Containers

docker container kill nginx

Sending another signal

docker container kill -s HUP nginx

Connecting to an Existing Container

docker container attach nginx

Check the Containers

docker ps

To see all running containers

docker container ls

Container Logs

docker logs infinite

'tail -f' Containers' Logs

docker container logs infinite -f

Inspecting Containers

docker container inspect infinite

Inspecting Containers for certain

docker container inspect --format '{{ .NetworkSettings.IPAddress }}' $(docker ps -q)

Containers Events

docker system events infinite

docker system events infinite

docker container port infinite

Running Processes

docker container top infinite

Container Resource Usage

docker container stats infinite

Inspecting changes to files or directories on a container’s filesystem

docker container diff infinite

Docker Image Management Commands

Name

Command

Listing Images

docker image ls

Building Images

docker build.

From a Remote GIT Repository

docker build github.com/creack/docker-firefox

Instead of Specifying a Context, You Can Pass a Single Dockerfile in the URL or Pipe the File in via STDIN

docker build - < Dockerfile

Building and Tagging

docker build -t eon/infinite.

Building a Dockerfile while Specifying the Build Context

docker build -f myOtherDockerfile.

Building from a Remote Dockerfile URI

curl example.com/remote/Dockerfile | docker build -f - .

Removing an Image

docker image rm nginx

Loading a Tarred Repository from a File or the Standard Input Stream

docker image load < ubuntu.tar.gz

Saving an Image to a Tar Archive

docker image save busybox > ubuntu.tar

Showing the History of an Image

docker image history

Creating an Image From a Container

docker container commit nginx

Tagging an Image

docker image tag nginx eon01/nginx

Pushing an Image

docker image push eon01/nginx

Docker Network Commands

Name

Command

Creating an Overlay Network

docker network create -d overlay MyOverlayNetwork

Creating a Bridge Network

docker network create -d bridge MyBridgeNetwork

Creating a Customized Overlay Network

docker network create -d overlay \

--subnet=192.168.0.0/16 \

--subnet=192.170.0.0/16 \

--gateway=192.168.0.100 \

--gateway=192.170.0.100 \

--ip-range=192.168.1.0/24 \

--aux-address="my-router=192.168.1.5"

--aux-address="my-switch=192.168.1.6" \

--aux-address="my-printer=192.170.1.5"

--aux-address="my-nas=192.170.1.6" \ MyOverlayNetwork

Removing a Network

docker network rm MyOverlayNetwork

Listing Networks

docker network ls

Getting Information About a Network

docker network inspect MyOverlayNetwork

Connecting a Running Container to a Network

docker network connect MyOverlayNetwork nginx

Connecting a Container to a Network When it Starts

docker container run -it -d --network=MyOverlayNetwork nginx

Disconnecting a Container from a Network

docker network disconnect MyOverlayNetwork nginx

Docker Exposing Ports Commands

Name

Command

Exposing Ports

EXPOSE <port_number>

Mapping Ports

docker run -p $HOST_PORT:$CONTAINER_PORT --name <container_name> -t <image>

Docker Commands Removing Containers, Images, Volumes, And Networks

Name

Command

Removing a Running Container

docker container rm nginx

Removing a Container and its Volume

docker container rm -v nginx

Removing all Exited Containers

docker container rm $(docker container ls -a -f status=exited -q)

Removing All Stopped Containers

docker container rm `docker container ls -a -q`

Removing a Docker Image

docker image rm nginx

Removing Dangling Images

docker image rm $(docker image ls -f dangling=true -q)

Removing all Images

docker image rm $(docker image ls -a -q)

Removing all Untagged Images

docker image rm -f $(docker image ls | grep "^" | awk "{print $3}")

Stopping & Removing all Containers

docker container stop $(docker container ls -a -q) && docker container rm $(docker container ls -a -q)

Removing Dangling Volumes

docker volume rm $(docker volume ls -f dangling=true -q)

Removing all unused (containers, images, networks and volumes)

docker system prune -f

Clean all

docker system prune -a

Docker Swarm Commands

Name

Command

Installing Docker Swarm

curl -ssl https://get.docker.com | bash

Initializing the Swarm

docker swarm init --advertise-addr 192.168.10.1

Getting a Worker to Join the Swarm

docker swarm join-token worker

Getting a Manager to Join the Swarm

docker swarm join-token manager

Listing Services

docker service ls

Listing nodes

docker node ls

Creating a Service

docker service create --name vote -p 8080:80 instavote/vote

Listing Swarm Tasks

docker service ps

Scaling a Service

docker service scale vote=3

Updating a Service

docker service update --image instavote/vote:movies vote

Updating a Service

docker service update --force --update-parallelism 1 --update-delay 30s nginx

Docker file Commands

Command

Description

Example

FROM

Specifies the base image for the build

FROM ubuntu:latest

RUN

Executes a command inside the container during build time

RUN apt-get update && apt-get install -y curl

CMD

Specifies the default command to run when the container starts

CMD ["npm", "start"]

EXPOSE

Informs Docker that the container listens on specific network ports at runtime

EXPOSE 80/tcp

ENV

Sets environment variables inside the container

ENV NODE_ENV=production

COPY

Copies files or directories from the build context into the container

COPY app.js /usr/src/app/

ADD

Similar to COPY but supports additional features like URL retrieval and decompression

ADD https://example.com/file.tar.gz /usr/src/

WORKDIR

Sets the working directory for subsequent instructions

WORKDIR /usr/src/app

ARG

Defines variables that users can pass at build-time to the builder with the docker build command

ARG VERSION=1.0

ENTRYPOINT

Configures a container to run as an executable

ENTRYPOINT ["python", "app.py"]

VOLUME

Creates a mount point and assigns it to a specified volume

VOLUME /data

USER

Sets the user or UID to use when running the image

USER appuser

LABEL

Adds metadata to an image in the form of key-value pairs

LABEL version="1.0" maintainer="John Doe

ONBUILD

Configures commands to run when the image is used as the base for another build

ONBUILD ADD . /app/src

Docker Volume Commands

Command

Description

Example

volume create

Creates a named volume

docker volume create mydata

volume ls

Lists the available volumes

docker volume ls

volume inspect

Displays detailed information about a volume

docker volume inspect mydata

volume rm

Removes one or more volumes

docker volume rm mydata

volume prune

Removes all unused volumes

docker volume prune

Docker CP commands

Command

Description

Example

docker cp [OPTIONS] SRC_PATH CONTAINER:DEST_PATH

Copies files or directories from the local filesystem to the specified container

docker cp myfile.txt mycontainer:/usr/src/app/

docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH

Copies files or directories from the specified container to the local filesystem

docker cp mycontainer:/usr/src/app/result.txt /tmp/result/

Docker Security Commands (Docker Scout)

Command

Description

Example

docker scout compare

[experimental] Compare two images and display differences

docker scout compare image1:tag image2:tag

docker scout cves

Display CVEs identified in a software artifact

docker scout cves image: tag

docker scout Quickview

Quick overview of an image

docker scout quickview image: tag

docker scout recommendations

Display available base image updates and remediation recommendations

docker scout recommendations image:tag

docker scout version

Show Docker Scout version information

docker scout version

Conclusion

In conclusion, this Docker cheat sheet helps you with a quick revision of all the Docker commands that are required for Docker operations, including Docker installation, building, running, shipping, and cleaning up, as well as interaction with containers.


Next Article
C++ Cheatsheet

K

kartik
Improve
Article Tags :
  • Docker
  • DevOps
  • docker
  • GFG Sheets

Similar Reads

    Geeksforgeeks Cheatsheets - All Coding Cheat Sheets Collections
    Cheatsheets are short documents that contain all the most essential information about a specific technology in short, such as its syntax, commands, functions, or its features. Sheets are designed to help users to learn quickly and these Sheets are given the basics Overview of the technology without
    4 min read
    Subnet Mask Cheat Sheet
    A Subnet Mask is a numerical value that describes a computer or device's how to divide an IP address into two parts: the network portion and the host portion. The network element identifies the network to which the computer belongs and the host part identifies the unique computer on that network. An
    9 min read
    Git Cheat Sheet
    Git Cheat Sheet is a comprehensive quick guide for learning Git concepts, from very basic to advanced levels. By this Git Cheat Sheet, our aim is to provide a handy reference tool for both beginners and experienced developers/DevOps engineers. This Git Cheat Sheet not only makes it easier for newcom
    10 min read
    NumPy Cheat Sheet: Beginner to Advanced (PDF)
    NumPy stands for Numerical Python. It is one of the most important foundational packages for numerical computing & data analysis in Python. Most computational packages providing scientific functionality use NumPy’s array objects as the lingua franca for data exchange. In this Numpy Cheat sheet f
    15+ min read
    Linux Commands Cheat Sheet
    Linux, often associated with being a complex operating system primarily used by developers, may not necessarily fit that description entirely. While it can initially appear challenging for beginners, once you immerse yourself in the Linux world, you may find it difficult to return to your previous W
    13 min read
    Pandas Cheat Sheet for Data Science in Python
    Pandas is a powerful and versatile library that allows you to work with data in Python. It offers a range of features and functions that make data analysis fast, easy, and efficient. Whether you are a data scientist, analyst, or engineer, Pandas can help you handle large datasets, perform complex op
    15+ min read
    Java Cheat Sheet
    Java is a programming language and platform that has been widely used since its development by James Gosling in 1991. It follows the Object-oriented Programming concept and can run programs written on any OS platform. Java is a high-level, object-oriented, secure, robust, platform-independent, multi
    15+ min read
    C++ STL Cheat Sheet
    The C++ STL Cheat Sheet provides short and concise notes on Standard Template Library (STL) in C++. Designed for programmers that want to quickly go through key STL concepts, the STL cheatsheet covers the concepts such as vectors and other containers, iterators, functors, etc., with their syntax and
    15+ min read
    Docker Cheat Sheet : Complete Guide (2024)
    Docker is a very popular tool introduced to make it easier for developers to create, deploy, and run applications using containers. A container is a utility provided by Docker to package and run an application in a loosely isolated environment. Containers are lightweight and contain everything neede
    10 min read
    C++ Cheatsheet
    This is a C++ programming cheat sheet. It is useful for beginners and intermediates looking to learn or revise the concepts of C++ programming. While learning a new language, it feels annoying to switch pages and find different websites for different concepts that are easily understandable. You can
    15 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences