Top 20 Essential Docker Commands You Should Know in 2025
Updated on Jun 12, 2025 | 26 min read | 14.42K+ views
Share:
For working professionals
For fresh graduates
More
Updated on Jun 12, 2025 | 26 min read | 14.42K+ views
Share:
Table of Contents
Do you know? Docker remains the undisputed leader in containerization, powering over 87% of the global container market and supporting more than 65,000 companies worldwide. This dominance underscores Docker’s essential role in modern software development and why mastering its commands is more valuable than ever. |
Developers, system administrators, and DevOps engineers are relying heavily on Docker in 2025. Its ability to containerize applications, isolate environments, and manage dependencies efficiently is crucial in today’s fast-paced development environment.
Especially for deploying microservices-based applications, Docker commands allow developers to package individual services in containers. For example, a company running multiple microservices can use Docker commands to ensure each service runs in its own isolated container, making it easier to scale, update, or debug them without affecting other services.
In this blog, you will explore the essential Docker commands every developer and DevOps professional should know in 2025. It will cover key commands that will help streamline your workflow and enhance your containerization skills.
As of 2025, Docker commands the containerization market with an 87.77% share, used by over 65,000 companies worldwide, including major enterprises such as AT&T, Wipro, and The Walt Disney Company. The platform’s ecosystem supports a massive developer community and is a key driver behind the rise of microservices, AI, and cloud-native architectures.
This widespread adoption has made Docker an essential tool for accelerating development, enhancing operational efficiency, and enabling teams to collaborate and deliver faster results.
In 2025, professionals who understand how to use essential Docker commands will be highly sought after. If you're looking to sharpen your skills and make the right choice between these powerful platforms, check out these top-rated courses to enhance your knowledge and stay competitive in the tech industry.
Here’s a brief overview of the 20 essential Docker commands you should know in 2025:
Docker Command |
Description |
docker run | Creates and starts a new container from an image, used for container initialization. |
docker ps | Lists all active containers, useful for monitoring running containers. |
docker images | Displays all Docker images stored locally, useful for viewing available images. |
docker stop | Stops a running container, commonly used to stop ongoing processes in containers. |
docker rm | Removes stopped containers, helping to clean up unused containers. |
docker rmi | Removes one or more Docker images from the local environment to reclaim space. |
docker build | Builds a Docker image from a Dockerfile, used for creating custom images. |
docker push | Pushes a Docker image to a remote registry, useful for sharing images. |
docker pull | Retrieves a Docker image from a registry to the local system. |
docker exec | Executes commands inside a running container, helpful for debugging or changes. |
docker logs | Displays logs for a running or stopped container, crucial for troubleshooting. |
docker stats | Shows real-time resource usage statistics for running containers. |
docker inspect | Provides detailed information about containers, images, or other Docker objects. |
docker history | Displays the history of an image, useful for understanding image layers and changes. |
docker commit | Creates a new image from a container’s current state, often used for saving changes. |
docker save | Saves a Docker image to a tarball, useful for transferring or backing up images. |
docker load | Loads a Docker image from a tarball, used to import saved Docker images. |
docker network | Manages networks, allowing communication between containers and external systems. |
docker volume | Manages persistent data storage for containers, essential for data-sharing between containers. |
docker compose | Defines and runs multi-container Docker applications using a YAML file. |
Next, let’s look at the essential Docker commands in more detail:
Learning basic Docker commands is essential for efficient application delivery and operational agility. Core commands such as running, listing, stopping, and removing containers, as well as managing images streamline workflows. They support the rapid deployment practices that have made Docker a standard in modern DevOps.
Below is a list of the most widely used essential Docker commands that every developer should know to manage containers, images, and the Docker environment effectively:
1. Docker Run
This command initiates creating and activating a fresh container using a Docker image. It provides options to configure aspects like port mappings, environment variables, and volume mounts.
For instance, the Docker run -d option is used to run a container in detached mode. When the Docker -d command is selected, the container operates in the background, enabling you to keep using the command prompt or the terminal without being connected to the container’s console.
Features:
Use Case: The docker run command is typically used to start a container based on an image. For example, when running a web application in a Docker container, you can map ports from the container to your local machine and set environment variables for configuration.
Example:
docker run -d -p 8080:80 --name my_web_app -e
"ENV=production" nginx
Explanation:
Output: After running the above command, the container will run in the background, and you can access the web server by visiting http://localhost:8080.
Interested in Java programming? upGrad’s free Core Java Basics course can help you. It covers variables, data types, loops, and OOP principles to build strong coding skills. Perfect for aspiring developers, students, and professionals transitioning to Java.
Also Read: What is Docker Container? Function, Components, Benefits & Evolution
2. Docker PS
The “docker ps” command is used to present data regarding the active containers on a Docker host. It offers insights such as container ID, utilised image, container status, port mapping, and resource usage. This command aids in monitoring running containers and acquiring vital information for Docker environment management.
Features:
Use Case: The docker ps command is often used to monitor the status of containers. For example, when managing a set of containers running different services, docker ps can help you check which containers are up, their status, and how they are mapped to the host machine.
Example:
docker ps
Explanation: Running docker ps will list all the currently running containers, displaying their container ID, the image they are based on, the status, and port mappings.
Output:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a1b2c3d4e5f6 nginx "nginx -g 'daemon of..." 2 hours ago Up 2 hours 0.0.0.0:8080->80/tcp my_web_app
In this output, the container ID is a1b2c3d4e5f6, it’s running the nginx image, has been up for 2 hours, and is mapped to port 8080 on the host machine.
3. Docker Images
The docker images command lists all the Docker images stored locally on your system. It provides essential information such as the image ID, repository name, tag, and creation date. This command is useful for managing and inspecting available images, and for determining which images are currently stored on your machine.
Features:
Use Case: The docker images command is typically used when you want to view all available images before creating or running containers. For example, before creating a new container, you can check which images are available to ensure you are using the correct one.
Example:
docker images
Explanation: Running docker images will show all images stored locally, including details like the image ID, repository name, tags, and size.
Output:
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest a1b2c3d4e5f6 2 days ago 133MB
ubuntu 20.04 b7f5b74f94fb 3 weeks ago 64.2MB
In this output, you can see the repository name (nginx), the tag (latest), the image ID (a1b2c3d4e5f6), the creation time, and the size of each image.
If you want to improve your knowledge of object-oriented programming, upGrad’s Java Object-oriented Programming can help you. Learn classes, objects, inheritance, polymorphism, encapsulation, and abstraction with practical programming examples.
Also Read: Introduction to Docker: What is, Architecture, Workflow
4. Docker Stop All Containers
This command is employed to halt all active containers simultaneously. By combining commands, it retrieves the IDs of running containers and then passes them to the “docker stop” command. Consequently, all currently running containers on the Docker host are stopped, offering a convenient means to halt multiple containers simultaneously.
Features:
Use Case: The docker stop command is useful when you need to shut down all active containers, perhaps during maintenance or before restarting the Docker service. By stopping all containers at once, you can ensure a clean environment.
Example:
docker stop $(docker ps -q)
Explanation:
Output:
a1b2c3d4e5f6
b7f8g9h0i1j2
In this output, the command stops the containers with IDs a1b2c3d4e5f6 and b7f8g9h0i1j2. The containers are halted and no longer active.
5. Docker RM
The docker rm command is used to remove one or more stopped containers from the system. It helps clean up unused containers, freeing up resources and maintaining a tidy Docker environment. This command is particularly useful after stopping containers, ensuring that obsolete or unnecessary containers do not consume disk space.
Features:
Use Case: The docker rm command is typically used when you want to delete stopped containers after their tasks are completed. For example, once a container is no longer needed for testing or development, you can remove it to free up resources.
Example:
docker rm my_web_app
Explanation:
Output:
my_web_app
In this output, the container my_web_app is successfully removed from the system, freeing up any associated resources.
Also Read: 14 Best Docker Project Ideas For Beginners [2025]
6. Docker RMI
The docker rmi command is used to remove one or more Docker images from the local environment. This helps reclaim disk space by deleting unused or outdated images, which can accumulate over time and consume significant storage. It’s an essential command for cleaning up and optimizing your Docker setup.
Features:
Use Case: The docker rmi command is commonly used when you no longer need a specific image, such as when updating an application’s image or clearing out old versions to save disk space.
Example:
docker rmi nginx:latest
Explanation:
Output:
Untagged: nginx:latest
Deleted: sha256:a1b2c3d4e5f6
In this output, the nginx:latest image is successfully removed, and the associated image layers are deleted, freeing up storage space.
7. Docker Build
This command constructs a new Docker image based on instructions provided in a Dockerfile. It may involve installing dependencies, configuring the environment, and copying application code.
Features:
Use Case: The docker build command is used when you need to create a custom Docker image for your application. For example, when developing a web application, you would write a Dockerfile to specify the base image, dependencies, and files to be copied into the container. Running docker build will create the image based on these instructions.
Example:
docker build -t my_custom_image .
Explanation:
Output:
Sending build context to Docker daemon 3.072kB
Step 1/5 : FROM ubuntu:20.04
...
Successfully built a1b2c3d4e5f6
Successfully tagged my_custom_image:latest
In this output, the build process executes each step from the Dockerfile and creates a new image with the name my_custom_image. The image is ready for use and deployment.
You can get a better understanding of Python programming with upGrad’s Learn Python Libraries: NumPy, Matplotlib & Pandas. Learn how to manipulate data using NumPy, visualize insights with Matplotlib, and analyze datasets with Pandas.
8. Docker Push
The docker push command is used to upload a Docker image to a registry, such as Docker Hub or a private registry. This allows you to share the image with others or deploy it in different environments, making it accessible across various machines or cloud platforms.
Features:
Use Case: The docker push command is commonly used after building a custom image that needs to be shared or deployed. For example, after creating a custom web application image, you might push it to Docker Hub or a private registry to make it available for deployment on other systems or servers.
Example:
docker push my_custom_image:latest
Explanation:
Output:
The push refers to repository [docker.io/my_custom_image]
a1b2c3d4e5f6: Pushed
latest: digest: sha256:abcd1234... size: 1234
In this output, the image my_custom_image:latest is successfully pushed to the registry, making it available for use in other environments.
9. Docker Pull
The docker pull command is used to retrieve a Docker image from a registry (like Docker Hub or a private registry) to the local system. This allows you to obtain a remotely stored image, which you can then use to create and run containers on your local machine.
Features:
Use Case: The docker pull command is often used to retrieve a base image for starting a new container. For example, you might use docker pull to fetch an official image like nginx or ubuntu to use as the foundation for your containerized application.
Example:
docker pull nginx:latest
Explanation:
Output:
latest: Pulling from library/nginx
a1b2c3d4e5f6: Pull complete
b7f8g9h0i1j2: Pull complete
Digest: sha256:abcd1234...
Status: Downloaded newer image for nginx:latest
In this output, the image nginx:latest is successfully pulled from the registry, and the container is ready to be used locally.
Are you looking to gain a foothold in DevOps? Check out upGrad’s online Executive Post Graduate Certificate in Cloud Computing and DevOps for professional guidance on DevOps and its fundamentals, including Docker.
Next, let’s look at some advanced essential Docker commands.
Advanced Docker commands serve the purpose of handling intricate container management operations. These include tasks like defining multi-container applications, managing networks and data storage, monitoring container performance, examining object details, and orchestrating container clusters.
Some of the most used advanced essential Docker commands have been listed below for your reference:
10. Docker Compose
This Docker tool is used for defining and controlling multi-container applications. It employs a YAML file to specify the necessary services, networks, and volumes for the application, simplifying the deployment process.
Features:
Use Case: The docker-compose command is useful for deploying complex applications that require multiple services to run together. For example, a typical web application might involve separate containers for the web server, database, and cache. Using docker-compose, you can define all these services in a single file and manage them together.
Example:
version: '3'
services:
web:
image: nginx
ports:
- "8080:80"
db:
image: postgres
environment:
POSTGRES_PASSWORD: example
To start the application:
docker-compose up
Explanation:
Output:
Creating network "myapp_default" with the default driver
Creating myapp_db_1 ... done
Creating myapp_web_1 ... done
In this output, Docker Compose creates and starts both the web and db containers, automatically setting up the network and volumes as defined in the docker-compose.yml file.
Also Read: Docker Python Script: Your Quick & Easy Guide for 2025!
11. Docker Network
This advanced command manages networks that enable communication between containers. It allows containers to interact with each other or external systems by connecting them to specific networks.
Features:
Use Case: The docker network command is commonly used when you need to isolate containers or enable communication between them. For example, in a microservices architecture, you may want to create a custom network so that only specific containers can communicate with each other while remaining isolated from others.
Example:
docker network create my_network
docker run -d --name web --network my_network nginx
docker run -d --name db --network my_network postgres
Explanation:
Output:
my_network
In this output, the custom network my_network is created, and the two containers are connected to it, ensuring they can communicate with each other while isolated from other containers not part of this network.
12. Docker Volume
This command handles persistent data storage for containers. It provides a means to store and share data between containers or between containers and the host system.
Features:
Use Case: The docker volume command is used when persistent storage is required, such as when running a database in a container. For example, you can use a volume to store a database's data files, so the data is not lost when the container is stopped or removed.
Example:
docker volume create my_data
docker run -d --name my_db -v my_data:/var/lib/postgresql/data postgres
Explanation:
Output:
my_data
In this output, the volume my_data is created and attached to the container, allowing persistent data storage for the PostgreSQL database even if the container is restarted or removed.
13. Docker Logs
The docker logs command retrieves the logs generated by a running or stopped container. It displays the output and error messages from the container, making it an essential tool for troubleshooting and debugging. By viewing logs, you can gain insights into container behavior, application status, and potential issues.
Features:
Use Case: The docker logs command is typically used to debug or monitor the behavior of containers. For example, if a web application container is crashing, you can use docker logs to check the error messages and identify the cause of the issue.
Example:
docker logs my_web_app
Explanation:
Output:
2025/06/09 12:45:23 [INFO] Server started on port 80
2025/06/09 12:45:25 [ERROR] Failed to connect to database: timeout
In this output, the logs indicate that the server started successfully on port 80 but encountered an error while connecting to the database, helping diagnose the issue.
Also Read: Docker vs Container: Difference Between Docker and Container
14. Docker Exec
This command executes commands within a running container. It facilitates interactive or detached execution of commands, useful for tasks like debugging or configuration changes.
Features:
Use Case: The docker exec command is often used when you need to make quick changes inside a running container or troubleshoot an issue without stopping the container. For example, you may need to access a container to install a missing dependency or check logs directly from within the container.
Example:
docker exec -it my_web_app bash
Explanation:
Output:
root@a1b2c3d4e5f6:/#
In this output, you've successfully accessed the shell of the my_web_app container, where you can run commands, inspect files, or perform other operations directly inside the container.
Also Read: MongoDB Docker Compose: Quick Setup Guide for 2025
15. Docker Stats
This command presents real-time resource usage statistics for running containers. It offers information on CPU, memory, and network utilisation, assisting in monitoring and optimising container performance.
Features:
Use Case: The docker stats command is commonly used to monitor the resource usage of containers in production or during heavy workloads. For example, if a container is consuming too much memory or CPU, this command allows you to track usage and make adjustments to improve efficiency.
Example:
docker stats my_web_app
Explanation:
Output:
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O
a1b2c3d4e5f6 my_web_app 2.5% 100MiB / 1GiB 9.8% 1.2MB / 500KB 2.3MB / 0B
In this output, you can see the CPU usage (2.5%), memory usage (100MB out of 1GB), and network I/O (1.2MB received). This helps identify any containers that might be consuming excessive resources.
16. Docker Inspect
The docker inspect command provides detailed information about Docker objects, such as containers, images, networks, and volumes. It offers an extensive view of configuration details, network settings, environment variables, and other object-specific information. This makes it a powerful tool for debugging and monitoring Docker environments.
Features:
Use Case: The docker inspect command is useful when you need to investigate the configuration of a container, image, or network. For instance, if you need to examine the network settings of a container or find out the environmental variables of a running container, this command provides all the necessary details.
Example:
docker inspect my_web_app
Explanation:
Output:
[
{
"Id": "a1b2c3d4e5f6",
"Created": "2025-06-09T12:45:23.000000000Z",
"Path": "nginx",
"Args": [
"-g",
"daemon off;"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false
},
"NetworkSettings": {
"Networks": {
"bridge": {
"IPAddress": "172.17.0.2"
}
}
},
"Mounts": [
{
"Source": "/var/lib/docker/volumes/my_volume/_data",
"Destination": "/usr/share/nginx/html",
"Mode": "rw"
}
]
}
]
In this output, you can see detailed information about the container’s ID, creation time, running status, network settings (e.g., IP address), and volume mounts. This is useful for debugging issues or verifying configuration details.
Also Read: Kubernetes Vs. Docker: Primary Differences You Should Know
17. Docker History
The docker history command reveals an image’s construction history, showing all the layers and commands used to build the image. This helps in understanding the image's size, its dependencies, and any modifications made during its creation. It's particularly useful for optimizing images and understanding the changes made across different versions.
Features:
Use Case: The docker history command is typically used to inspect how an image was built and to check the size of individual layers. This can help identify unnecessary layers or dependencies that could be removed to optimize the image.
Example:
docker history nginx:latest
Explanation:
Output:
IMAGE CREATED CREATED BY SIZE
a1b2c3d4e5f6 2 days ago /bin/sh -c #(nop) CMD ["nginx" "-g" "daemon off;"] 0B
b7f8g9h0i1j2 2 days ago /bin/sh -c #(nop) EXPOSE 80/tcp 0B
c3d4e5f6g7h8 2 days ago /bin/sh -c apt-get update && apt-get install -y curl 50MB
...
In this output, you can see the different layers that make up the nginx:latest image, the commands executed for each layer, and the size of each layer. This information helps in understanding how the image was built and where optimizations can be made.
18. Docker Commit
The docker commit command creates a new image from changes made to a running container, preserving its current state. This allows you to capture the configuration and modifications within a container, enabling you to store and share the modified container as a new image for further use or deployment.
Features:
Use Case: The docker commit command is often used when you need to save modifications made to a container. For instance, after installing new software or modifying configuration files inside a container, you can use this command to create a new image with those changes, which can then be shared or deployed.
Example:
docker commit my_container my_new_image:latest
Explanation:
Output:
sha256:abcd1234efgh5678ijklmnopqrstuvwx
In this output, a new image is created with the ID sha256:abcd1234efgh5678ijklmnopqrstuvwx, based on the current state of the container my_container. This image can now be used for future container deployments or shared with others.
19. Docker Save/Load
The docker save and docker load commands are used to export and import Docker images in the form of tarball files. These commands are useful for transferring Docker images between systems or environments, especially when internet access to a registry is unavailable, or you want to back up an image.
Features:
Use Case: The docker save and docker load commands are used when you need to share a Docker image between systems that don't have direct access to a Docker registry. For example, you can save a custom image to a tarball, transfer it to a different machine, and then use docker load to import it there.
Example (docker save):
docker save -o my_image.tar my_custom_image:latest
Explanation:
Example (docker load):
docker load -i my_image.tar
Explanation:
Output (docker save):
my_image.tar
Output (docker load):
Loaded image: my_custom_image:latest
In these outputs, the docker save command creates a tarball of the my_custom_image:latest, and docker load successfully imports the image into the Docker environment. This makes it easy to transfer and deploy Docker images between different systems.
Also Read: Kubernetes Architecture: Everything You Need to Know
20. Docker Swarm
The docker swarm command is used to create and manage a cluster of Docker nodes. It facilitates container orchestration and scalability by allowing containers to be deployed, managed, and scaled across multiple hosts in a Docker Swarm cluster.
Docker Swarm helps simplify the deployment of complex applications across multiple systems, ensuring high availability and load balancing.
Features:
Use Case: The docker swarm command is typically used when deploying large-scale applications that require high availability and automatic scaling. For example, when you need to deploy a microservices-based architecture across multiple machines, Docker Swarm can coordinate the deployment and scaling of services across the cluster.
Example (Initialize a Swarm):
docker swarm init
Explanation: docker swarm init initializes a new Swarm on the current machine, making it the first manager node of the cluster.
Example (Join a Swarm):
docker swarm join --token <SWARM_TOKEN> <MANAGER_IP>:2377
Explanation: The docker swarm join command is used by worker nodes to join an existing Swarm cluster. The <SWARM_TOKEN> is a unique token generated by the manager node, and <MANAGER_IP> is the IP address of the manager node.
Output (docker swarm init):
Swarm initialized: current node (a1b2c3d4e5f6) is now a manager.
Output (docker swarm join):
This node joined a swarm as a worker.
In these outputs, docker swarm init sets up the Swarm, and docker swarm join allows additional nodes to join the cluster. With Docker Swarm, you can now deploy and manage services across multiple Docker nodes in a scalable and fault-tolerant manner.
Also Read: Kubernetes Cheat Sheet: Architecture, Components, Command Sheet
Now that you have a good understanding of the essential Docker commands, let’s look at some tips you can follow to improve usage.
Enterprises that implement Docker are witnessing a 126% ROI over three years and accelerating their time to market by three months compared to competitors. Conversely, skipping modern Docker workflows can result in overspending by up to 70% on cloud costs and deploying features five times slower.
As containerization becomes the standard, adhering to best practices when using essential Docker commands is critical for cost savings, speed, and staying competitive.
Let’s go through 5 actionable tips for using essential Docker commands:
1. Use the docker exec command to access a running container’s shell for real-time troubleshooting without interrupting its processes.
Use Case: In a production environment, if a container running a web application is showing errors, you can quickly access its shell using docker exec -it <container_name> bash. This allows you to inspect logs, check configurations, or fix issues without stopping the container.
2. Use the --squash flag during the docker build process to reduce image size by squashing image layers together.
Use Case: When building an image with multiple dependencies (e.g., installing libraries), the resulting image can have many layers, increasing its size. By using docker build --squash, you can merge the layers, improving the image’s efficiency for faster deployment.
3. Regularly run docker system prune to remove unused containers, networks, images, and volumes, keeping your Docker environment clean and optimized.
Use Case: During development, you might create multiple containers for testing. Over time, these containers and images can accumulate, consuming significant disk space. Running docker system prune clears out unnecessary resources, ensuring that your environment remains lean and performant.
4. Simplify the management of multi-container applications with docker-compose, which defines services, networks, and volumes in a single YAML file.
Use Case: For an application that uses both a web server and a database, docker-compose allows you to define both containers and their relationships in one file. Running docker-compose up will automatically start both containers, making it easy to manage the entire application stack.
5. Use the docker stats command to monitor the real-time resource usage of running containers, helping you identify performance bottlenecks.
Use Case: In a microservices architecture, one of your containers might start consuming excessive CPU or memory, affecting overall performance. By running docker stats, you can quickly see resource usage and take action, such as scaling containers or optimizing their resource limits.
Are you a full-stack developer wanting to integrate AI into your workflow? upGrad’s AI-Driven Full-Stack Development bootcamp can help you. You’ll learn how to build AI-powered software using OpenAI, GitHub Copilot, Bolt AI & more.
Also Read: Kubernetes Salary in India 2025: A Comprehensive Guide
Next, let’s look at how upGrad can help you learn how to efficiently use essential Docker commands.
Docker commands are essential for managing containers and optimizing deployment workflows in modern software development. Learning them enhances your technical skills and strengthens your portfolio, making you more competitive in the job market.
upGrad’s courses provide hands-on projects and expert guidance to help you master essential Docker commands. In addition to the courses covered above, here are some complementary free courses to enhance your skills:
If you're unsure where to begin or which area to focus on, upGrad’s expert career counselors can guide you based on your goals. You can also visit a nearby upGrad offline center to explore course options, get hands-on experience, and speak directly with mentors!
Boost your career with our popular Software Engineering courses, offering hands-on training and expert guidance to turn you into a skilled software developer.
Master in-demand Software Development skills like coding, system design, DevOps, and agile methodologies to excel in today’s competitive tech industry.
Stay informed with our widely-read Software Development articles, covering everything from coding techniques to the latest advancements in software engineering.
References:
https://www.bitcot.com/docker-in-cloud-computing/
https://www.docker.com/blog/lets-get-containerized/
https://6sense.com/tech/containerization
900 articles published
Director of Engineering @ upGrad. Motivated to leverage technology to solve problems. Seasoned leader for startups and fast moving orgs. Working on solving problems of scale and long term technology s...
Get Free Consultation
By submitting, I accept the T&C and
Privacy Policy
India’s #1 Tech University
Executive PG Certification in AI-Powered Full Stack Development
77%
seats filled
Top Resources