View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All

Top 20 Essential Docker Commands You Should Know in 2025

By Pavan Vadapalli

Updated on Jun 12, 2025 | 26 min read | 14.42K+ views

Share:

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.

Want to dive deeper into essential Docker commands and other programming essentials? Enroll in upGrad’s Online Software Development Courses and enhance your skills with hands-on projects that mirror real industry scenarios. Learn from the latest technologies and programming languages to choose the best platform.

20 Essential Docker Commands: A Complete Guide

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:

Basic Docker Commands

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.

Coverage of AWS, Microsoft Azure and GCP services

Certification8 Months

Job-Linked Program

Bootcamp36 Weeks

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:

  • Runs containers in detached mode (-d).
  • Maps ports between host and container (-p).
  • Supports setting environment variables (-e).

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:

  • -d runs the container in detached mode.
  • -p 8080:80 maps port 8080 on the local machine to port 80 in the container, allowing access to the container's web service on localhost:8080.
  • --name my_web_app gives the container a specific name, making it easier to manage.
  • -e "ENV=production" sets an environment variable within the container for production settings.

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:

  • Lists active containers and their details.
  • Displays container ID, image, status, and port mapping.
  • Allows filtering for specific containers with additional options.

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:

  • Displays local Docker images with ID, repository, and tag.
  • Shows image size and creation time.
  • Allows filtering and sorting of images.

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:

  • Stops one or more running containers.
  • Can stop all containers by chaining commands.
  • Helps in bulk container management and cleanup.

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:

  • docker ps -q retrieves the IDs of all currently running containers.
  • docker stop $(docker ps -q) stops all containers by passing their IDs to the docker stop command.

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:

  • Removes one or more stopped containers.
  • Frees up disk space by cleaning up unused containers.
  • Can be combined with other commands to automate container removal.

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:

  • my_web_app is the name of the stopped container you wish to remove.
  • The docker rm command deletes the specified container from the system.

Output:

my_web_app

In this output, the container my_web_app is successfully removed from the system, freeing up any associated resources.

If you want to build a higher-level understanding of programming languagesupGrad’s Learn Basic Python Programming course is what you need. You will master fundamentals with real-world applications & hands-on exercises. Ideal for beginners, this Python course also offers a certification upon completion.

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:

  • Deletes one or more Docker images from the local system.
  • Frees up disk space by removing unused images.
  • Can be used with image IDs or repository names.

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:

  • nginx:latest specifies the image name and tag that you want to remove.
  • The docker rmi command removes the image from the local system.

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:

  • Builds a Docker image from a Dockerfile.
  • Allows customization of the image with dependencies, configurations, and application code.
  • Supports caching for faster builds on subsequent runs.

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:

  • -t my_custom_image tags the image with the name my_custom_image.
  • . refers to the current directory where the Dockerfile is located, which contains the build instructions.

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:

  • Uploads Docker images to a registry.
  • Enables sharing of images across different environments or with teams.
  • Works with public and private registries for image distribution.

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:

  • my_custom_image:latest is the name and tag of the image you want to push.
  • The image will be uploaded to the default Docker registry (Docker Hub) or a private registry if configured.

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:

  • Downloads Docker images from a registry.
  • Useful for fetching official or pre-built images.
  • Supports public and private registry access.

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:

  • nginx:latest specifies the image name (nginx) and the tag (latest), which is pulled from the Docker registry.
  • This command downloads the nginx image and makes it available on the local machine for container creation.

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

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:

  • Defines multi-container applications using a single YAML file.
  • Supports managing services, networks, and volumes for complex setups.
  • Allows easy start, stop, and scale of multiple containers with a single command.

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:

  • This docker-compose.yml file defines two services: web (using the nginx image) and db (using the postgres image).
  • The web service is mapped to port 8080 on the host.
  • The db service uses an environment variable to set the database password.

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.

If you are a programmer wanting to build a higher-level understanding of Javascript, upGrad’s Advanced Javascript for All course is what you need. Learn about prototypes, scopes, classes, modules, async programming, and more to enhance your web development skills and become a proficient JS developer.

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:

  • Creates, inspects, and manages Docker networks.
  • Allows containers to communicate with each other across networks.
  • Supports different network drivers (bridge, host, overlay, etc.) for varied use cases.

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:

  • docker network create my_network creates a custom network named my_network.
  • The web container (nginx) and the db container (postgres) are both connected to my_network, enabling them to communicate securely.

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:

  • Stores data outside of containers, ensuring persistence across container restarts.
  • Supports sharing data between containers or between containers and the host system.
  • Manages and cleans up unused volumes to reclaim disk space.

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:

  • docker volume create my_data creates a persistent volume named my_data.
  • The -v my_data:/var/lib/postgresql/data flag mounts the my_data volume to the PostgreSQL data directory inside the container, ensuring that database data is stored persistently.

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:

  • Displays container output, including standard output (stdout) and error messages (stderr).
  • Supports real-time log streaming.
  • Allows filtering logs by time or container ID.

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:

  • my_web_app is the name of the container.
  • The command retrieves the logs for the specified container, displaying the application's output or error messages.

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:

  • Executes commands inside a running container.
  • Supports interactive mode with -it for terminal access.
  • Allows running background tasks or scripts within the container.

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:

  • -it allows interactive terminal access to the container.
  • my_web_app is the name of the running container.
  • bash starts a Bash shell inside the container.

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:

  • Displays real-time CPU, memory, and network usage statistics for containers.
  • Helps in monitoring the health and performance of running containers.
  • Provides detailed insights into resource consumption to optimize performance.

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:

  • my_web_app is the name of the container you want to monitor.
  • The command outputs real-time stats for the specified container, including CPU, memory, and network usage.

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:

  • Retrieves detailed information about Docker objects (containers, images, networks, volumes).
  • Provides configuration, settings, and metadata in JSON format.
  • Useful for troubleshooting, inspection, and understanding object configurations.

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:

  • my_web_app is the name of the container.
  • The command outputs detailed JSON information about the specified container, including its configuration, network settings, and mounted volumes.

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:

  • Displays the history of a Docker image, including layers and commands.
  • Shows the size of each layer and the timestamps of when they were created.
  • Helps analyze and optimize image layers for smaller image sizes and better performance.

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:

  • nginx:latest specifies the image whose history you want to inspect.
  • The command shows the layers of the image, the commands used to build those layers, and the size of each layer.

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:

  • Creates a new image from the state of a running container.
  • Captures changes made to the container, such as installed packages or configuration updates.
  • Useful for saving container changes before stopping or removing a container.

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:

  • my_container is the name of the running container from which you want to create a new image.
  • my_new_image:latest is the name and tag of the new image that will be created.

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:

  • docker save: Exports a Docker image to a tarball file.
  • docker load: Imports a Docker image from a tarball file.
  • Facilitates transferring and backing up Docker images across systems.

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:

  • -o my_image.tar specifies the output tarball file.
  • my_custom_image:latest is the image being exported.

Example (docker load):

docker load -i my_image.tar

Explanation:

  • -i my_image.tar specifies the tarball file to import.

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:

  • Creates and manages a cluster of Docker nodes (a swarm).
  • Supports scaling and load balancing of containers across nodes.
  • Provides high availability and fault tolerance for containerized applications.

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.

You can also build relevant UI/UX skills for advanced web development with upGrad’s Master of Design in User Experience. You’ll learn to create user-centered designs that are innovative, efficient, and aligned with current industry trends, ensuring that your designs are not only functional but also impactful.

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.

5 Tips for Using Essential Docker Commands Effectively

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.

How Can upGrad Help You Use Docker Commands Efficiently?

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

Frequently Asked Questions (FAQs)

1. How can I optimize the build time when using docker build?

2. How do I handle log management for containers in a production environment?

3. What is the best way to clean up unused Docker images and containers?

4. Can I scale containers with essential Docker commands? How?

5. How can I connect multiple Docker containers for inter-service communication?

6. How can I automate the removal of stopped containers?

7. How do I limit resource usage for Docker containers?

8. How do I manage multiple Docker environments with different configurations?

9. What should I do if docker ps shows containers that aren’t running?

10. How do I share Docker images between systems that don’t have internet access?

11. How can I monitor container performance in real-time?

Pavan Vadapalli

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

+91

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

View Program

Top Resources

Recommended Programs

upGrad

AWS | upGrad KnowledgeHut

AWS Certified Solutions Architect - Associate Training (SAA-C03)

69 Cloud Lab Simulations

Certification

32-Hr Training by Dustin Brimberry

upGrad

Microsoft | upGrad KnowledgeHut

Microsoft Azure Data Engineering Certification

Access Digital Learning Library

Certification

45 Hrs Live Expert-Led Training

upGrad

upGrad KnowledgeHut

Professional Certificate Program in UI/UX Design & Design Thinking

#1 Course for UI/UX Designers

Bootcamp

3 Months