View All
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 2024

By Pavan Vadapalli

Updated on Jun 15, 2023 | 7 min read | 14.2k views

Share:

Introduction

Docker commands are crucial containerisation tools that allow programs to operate smoothly across numerous environments. With these commands, programmers can easily construct, deploy and manage containers. They also enable developers to create container images, orchestrate containerised applications, and instantiate containers.

Developers containerise their dependencies and programs in self-contained units with Docker commands because it guarantees reliable and consistent deployment. Docker commands make it easier to manage software applications, allowing for shorter development cycles, more scalability, and greater portability across several computer environments

This blog serves as a guide explaining in detail what docker commands are and their purpose. It also provides a holistic Docker commands list with examples.

What Is Docker and Why Is It Important?

Docker is an open-source platform that uses containerisation to simplify application creation, packaging, and deployments. It enables developers to package their applications and dependencies into isolated and portable units known as containers.

A container is a software element that combines code and its dependencies, allowing the application to run irrespective of the underlying system. It encapsulates the application and its dependencies into a self-contained unit, ensuring compatibility across different environments.

Docker is highly beneficial because it ensures consistency throughout environments and enables programs to operate systematically on any machine. It has a standardised environment that encourages cooperation among development teams and helps maintain consistent outcomes. Through containerisation, it improves scalability by optimising resource use. Docker also simplifies deployment, making applications run faster and improving operational efficiency.

Overall, Docker transforms application development by offering an adaptable, effective, and portable approach to developing and distributing applications.

Setting Up Docker Environment

Establishing a Docker environment is significant due to its ability to create isolated containers, ensuring consistent application deployment. It simplifies dependency management, optimises scalability and resource utilisation, fosters collaboration, and streamlines the development and deployment process, resulting in improved productivity and reliable application deployment.

Follow the steps below to establish a Docker environment:

  1. Install Docker: Install Docker from the official Docker website, tailored to your specific operating system.
  2. Confirm Installation: Validate the Docker installation by executing the “docker version” command in a terminal or command prompt.
  3. Obtain Docker Images: Retrieve essential Docker images from Docker Hub using the “docker pull” command and the corresponding image name.
  4. Formulate a Dockerfile: Craft a text file called “Dockerfile”, encompassing the necessary directives for constructing the desired container image.
  5. Construct the Docker Image: Execute the “docker build” command, specifying the directory housing the Dockerfile to fabricate the image.
  6. Launch Containers: Commence container instances based on the built images using the “docker run” command with suitable options.
  7. Manage Containers: Effectively handle containers using various Docker commands such as “docker ps” to enlist running containers and “docker stop” to halt their execution.

Basic Docker Commands

Basic Docker commands are essential for managing containers and images. They enable tasks such as running containers, listing running containers, managing images, stopping containers, removing containers, and interacting with containers. These commands facilitate container deployment, monitoring, and maintenance.

Here is a docker commands list of the basic yet most widely used ones that help manage containers, images, and the overall Docker environment:

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.

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.

Check out our free technology courses to upskill yourself

Docker images

This command displays a collection of Docker images stored locally. It showcases information like image ID, repository, and tag.

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.

Docker rm

This command deletes one or more stopped containers from the system. It aids in removing unnecessary containers and performing clean-up tasks.

Docker rmi

This command erases one or more Docker images from the local environment. This action reclaims storage space by eliminating specified images.

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.

Docker push

This command uploads a Docker image to a registry, like Docker Hub or a private registry. This facilitates sharing the image with others or deploying it in different environments

Learn Software Development Courses online from the World’s top Universities. Earn Executive PG Programs, Advanced Certificate Programs or Masters Programs to fast-track your career.

Docker pull

This command retrieves a Docker image from a registry to the local system. This enables obtaining a remotely stored image for running containers on the local machine.

Are you looking to gain a foothold in DevOps? Check out the online DevOps Bootcamp – Advanced Certificate Program for professional guidance on DevOps and its fundamentals, including Docker.

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. Consider signing up for the Master of Science in Computer Science from LJMU to learn more about advanced Docker commands.

Some of the most used advanced Docker commands have been listed below for your reference:

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.

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.

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.

Docker logs

This command retrieves container-generated logs, displaying output and error messages. This aids in troubleshooting and debugging by providing insights into a running container’s activities.

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.

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.

Docker inspect

This command provides detailed information about Docker objects, including containers, images, networks, and volumes. It offers an extensive view of configuration, network settings, and other object-specific details.

Docker history

This command reveals an image’s construction history, including layers and commands used. It aids in understanding an image’s size, dependencies, and modifications made throughout its development.

Docker commit

This command creates a new image from changes made to a running container, preserving its current state. This enables the storage and sharing of modified containers as new images.

Docker save/load

Coverage of AWS, Microsoft Azure and GCP services

Certification8 Months
View Program

Job-Linked Program

Bootcamp36 Weeks
View Program

This command archives and restores Docker images to/from a tarball file. It facilitates exporting and importing Docker images and making them transferable across different Docker environments.

Docker swarm

This command facilitates the creation and management of a cluster of Docker nodes. It supports container orchestration and scalability, allowing for the deployment and administration of containers across multiple hosts in a swarm cluster.

Conclusion

Docker commands are critical components of the containerisation ecosystem and allow developers to build, supervise, and deploy applications effortlessly. They are indispensable for reaping the full benefits of containerisation, allowing developers to bundle and distribute apps across several environments effectively. With a wide range of Docker tools, developers can create and manage containers and achieve consistency, expansion, and portability by facilitating smooth deployment and cooperation.

You can explore the Executive PG Programme in Full Stack Development from IIITB presented by upGrad for a comprehensive understanding of Docker tools. This program, carefully crafted by professionals in the field, offers an opportunity to enhance your skills and obtain valuable certifications to propel your professional journey forward. Sign up today.

Frequently Asked Questions (FAQs)

1. Which Docker commands are commonly used by developers?

2. How can one view the Docker container logs?

3. Can a Docker container be renamed?

Pavan Vadapalli

899 articles published

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

View Program
upGrad

Microsoft | upGrad KnowledgeHut

Microsoft Azure Data Engineering Certification

Access Digital Learning Library

Certification

45 Hrs Live Expert-Led Training

View Program
upGrad

upGrad KnowledgeHut

Professional Certificate Program in UI/UX Design & Design Thinking

#1 Course for UI/UX Designers

Bootcamp

3 Months

View Program