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
  • DevOps Lifecycle
  • DevOps Roadmap
  • Docker Tutorial
  • Kubernetes Tutorials
  • Amazon Web Services [AWS] Tutorial
  • AZURE Tutorials
  • GCP Tutorials
  • Docker Cheat sheet
  • Kubernetes cheat sheet
  • AWS interview questions
  • Docker Interview Questions
  • Ansible Interview Questions
  • Jenkins Interview Questions
Open In App
Next Article:
Running Commands Inside Docker Container
Next article icon

Docker Commands

Last Updated : 22 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Docker is an open-source project that automates the deployment of applications as movable, independent containers that can run locally or in the cloud. You can divide your applications from your infrastructure with the help of Docker, allowing for quick software delivery and it also allows you to manage your infrastructure in the same ways that you manage your applications.

 The number of commands found in docker is very huge in number, but we will be looking at the top commands in docker. To know more about Docker commands refer to Docker Cheat Sheet – Most Important Docker Commands.

Docker Commands

Docker Run command

This command is used to run a container from an image. The docker run command is a combination of the docker create and docker start commands. It creates a new container from the image specified and starts that container. if the docker image is not present, then the docker run pulls that.

$ docker run <image_name>
To give name of container
$ docker run --name <container_name> <image_name>
docker run image
 

Docker Pull

This command allows you to pull any image which is present in the official registry of docker, Docker hub. By default, it pulls the latest image, but you can also mention the version of the image.

$ docker pull <image_name>
Redis image latest version
 

Docker PS

This command (by default) shows us a list of all the running containers. We can use various flags with it.

  • -a flag:  shows us all the containers, stopped or running.
  • -l flag: shows us the latest container.
  • -q flag: shows only the Id of the containers. 
$ docker ps [options..]
Running Containers
 

Docker Stop

This command allows you to stop a container if it has crashed or you want to switch to another one.

$ docker stop <container_ID>
docker stop image

Docker Start

Suppose you want to start the stopped container again, you can do it with the help of this command.

$ docker start <container_ID>

Docker rm

To delete a container. By default when a container is created, it gets an ID as well as an imaginary name such as confident_boyd, heuristic_villani, etc. You can either mention the container name or its ID.

Some important flags:

  • -f flag: remove the container forcefully.
  • -v flag: remove the volumes.
  • -l flag: remove the specific link mentioned.
$ docker rm {options} <container_name or ID>
docker remove an image

Docker RMI

To delete the image in docker. You can delete the images which are useless from the docker local storage so you can free up the space

docker rmi <image ID/ image name>

Docker Images

Lists all the pulled images which are present in our system.

$ docker images
docker images metadata

Docker exec

This command allows us to run new commands in a running container. This command only works until the container is running, after the container restarts, this command does not restart.

Some important flags:

  • -d flag: for running the commands in the background.
  • -i flag: it will keep STDIN open even when not attached.
  • -e flag: sets the environment variables 
$ docker exec {options}
ubuntu containerexec command

Docker Ports (Port Mapping)

In order to access the docker container from the outside world, we have to map the port on our host( Our laptop for example), to the port on the container. This is where port mapping comes into play.

$ docker run -d -p <port_on_host> 
<port_on_container> Container_name
port 8080 on the host is mapped to container

So these were the 9 most basic docker commands that every beginner must know. Containerization is a very vast topic but you can start from the very basic commands and by practicing them daily you can master them.

Docker Login

The Docker login command will help you to authenticate with the Docker hub by which you can push and pull your images.

docker login 

It will ask you to enter the username and password after that you will authenticate with DockerHub and you can perform the tasks.

Docker Push

Once you build your own customized image by using Dockerfile you need to store the image in the remote registry which is DockerHub for that you need to push your image by using the following command. To know more about How to Push a Container Image to a Docker Repository?

docker push <Image name/Image ID> 

Docker Build

The docker build command is used to build the docker images with the help of Dockerfile.

docker build -t image_name:tag .

In the place of image_name use the name of the image you build with and give the tag number and . "dot" represents the current directory.

Docker Stop

You can stop and start the docker containers where you can do the maintenance for containers. To stop and start specific containers you can use the following commands.

docker stop container_name_or_id

Stop Multiple Containers

Instead of stopping a single container. You can stop multiple containers at a time by using the following commands.

docker stop container1 container2 container3

Docker Restart

While running the containers in Docker you may face some errors and containers fails to start. You can restart the containers to resolve the containers by using the following commands.

docker restart container_name_or_id

Docker Inspection

Docker containers will run into some errors in real time to debug the container's errors you can use the following commands.

docker inspect container_name_or_id

Docker Commit command

After running the containers by using the current image you can make the updates to the containers by interacting with the containers from that containers you can create an image by using the following commands.

docker commit container_name_or_id new_image_name:tag

Docker Basic Command

Following are the some of the docker basic commands

  1. docker images: Docker images will list all the images which are pulled or build in that docker host.
  2. docker pull: Docker pull will the docker images from the dockerhub.
  3. docker run: Docker run will run the docker image as an container.
  4. docker ps: Docker run will list all the containers which are running in the docker host.
  5. docker stop: Docker stop will stop the docker container which are already running.
  6. docker rm: Docker rm command will remove the containers which are in the stop condition.

Docker Commands List

Following are the docker commands which listed form build and Docker image to running it an Docker container and attaching the docker volumes to it.

Docker Image Command

  1. docker build command: It will build Docker images by using the Dockerfile.
  2. docker pull command: Docker pull command will pull the Docker image whcih is avalible in the dockerhub.
  3. docker images command: It will list all the images which are pulled and build in the docker host.
  4. docker inspect command: It will helps to debug the docker image if any errors occurred while building an image or pulling the image.
  5. docker push command: Docker command will push the docker image into the Dockerhub.
  6. docker save command: It will save the docker image in the form of dockerfile.
  7. docker rmi command: It will remove the docker image.

Docker Container Command

  1. docker attach command: Connecting to an Existing Container.
  2. docker ps command: To list the running containers.
  3. docker container inspect infinite Command: To Inspect the Docker containers.
  4. docker exec command: To execute the commands in the running containers.
  5. docker cp command: To copy the file from docker host to the docker containers,

Next Article
Running Commands Inside Docker Container

M

mukulojha
Improve
Article Tags :
  • Docker
  • DevOps

Similar Reads

    What is Docker?
    Have you ever wondered about the reason for creating Docker Containers in the market? Before Docker, there was a big issue faced by most developers whenever they created any code that code was working on that developer computer, but when they try to run that particular code on the server, that code
    12 min read

    Introduction to Docker

    What is Docker?
    Have you ever wondered about the reason for creating Docker Containers in the market? Before Docker, there was a big issue faced by most developers whenever they created any code that code was working on that developer computer, but when they try to run that particular code on the server, that code
    12 min read
    Features of Docker
    Pre-requisite: Docker Docker is one of the most popular open-source sets of platforms for developing and automating the deployment of applications. It deploys applications into containers and enables us to separate our applications from infrastructure. It is designed to provide a lightweight and fas
    4 min read
    Architecture of Docker
    Pre-requisite: DockerDocker makes use of a client-server architecture. The Docker client talks with the docker daemon which helps in building, running, and distributing the docker containers. The Docker client runs with the daemon on the same system or we can connect the Docker client with the Docke
    4 min read
    What is Docker Hub?
    Docker Hub is a repository service and it is a cloud-based service where people push their Docker Container Images and also pull the Docker Container Images from the Docker Hub anytime or anywhere via the internet. It provides features such as you can push your images as private or public. Mainly De
    12 min read
    What is Docker Cloud?
    Docker is a software platform that provides some special kind of facilities, like a service provider that allows you to build, test, and deploy your application in centralized processing and quickly. So, the Docker Cloud is basically working as a service provider by Docker in which we can perform su
    10 min read

    Docker Installation

    Docker - Installation on Windows
    In this article, we are going to see how to install Docker on Windows. On windows if you are not using operating system Windows 10 Pro then you will have to install our docker toolbox and here docker will be running inside a virtual machine and then we will interact with docker with a docker client
    2 min read
    How to Install Docker using Chocolatey on Windows?
    Installing Docker in Windows with just the CLI is quite easier than you would expect. It just requires a few commands. This article assumes you have chocolatey installed on your respective windows machine. If not, you can install chocolatey from here. Chocolatey is a package manager for the Windows
    4 min read
    How to Install and Configure Docker in Ubuntu?
    Docker is a platform and service-based product that uses OS-level virtualization to deliver software in packages known as containers. Containers are separated from one another and bundle their software, libraries, and configuration files. Docker is written in the Go language. Docker can be installed
    6 min read
    How to Install Docker on MacOS?
    Pre-requisites: Docker-Desktop Docker Desktop is a native desktop application for Windows and Mac's users created by Docker. It is the most convenient way to launch, build, debug, and test containerized apps. Docker Desktop includes significant and helpful features such as quick edit-test cycles, fi
    2 min read
    How to install and configure Docker on Arch-based Linux Distributions(Manjaro) ?
    In this article, we are going to see how to install and configure Docker on Arch-based Linux Distributions. Docker is an open-source containerization platform used for building, running, and managing applications in an isolated environment. A container is isolated from another and bundles its softwa
    2 min read
    How to Install Docker-CE in Redhat 8?
    Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all the parts it needs, such as libraries and other dependencies, and deploy it as one package. Installing Docker-CE in Redhat 8: St
    2 min read

    Docker Commands

    Docker Commands
    Docker is an open-source project that automates the deployment of applications as movable, independent containers that can run locally or in the cloud. You can divide your applications from your infrastructure with the help of Docker, allowing for quick software delivery and it also allows you to ma
    7 min read
    Running Commands Inside Docker Container
    If you are working on an application inside the Docker Container, you might need commands to install packages or access file system inside the Docker Container. Executing commands inside Docker Containers should be easy enough for you since you have to do it multiple times across your development ph
    6 min read
    Docker - USER Instruction
    By default, a Docker Container runs as a Root user. This poses a great security threat if you deploy your applications on a large scale inside Docker Containers. You can change or switch to a different user inside a Docker Container using the USER Instruction. For this, you first need to create a us
    2 min read

    Docker Images

    What is Docker Image?
    Docker Image is an executable package of software that includes everything needed to run an application. This image informs how a container should instantiate, determining which software components will run and how. Docker Container is a virtual environment that bundles application code with all the
    10 min read
    Working with Docker Images
    If you are a Docker developer, you might have noticed that working with multiple Docker Images at the same time might be quite overwhelming sometimes. Managing numerous Docker Images all through a single command line is a very hefty task and consumes a lot of time. In this article, we are going to d
    2 min read
    Docker - Publishing Images to Docker Hub
    Docker is a container platform that facilitates creating and managing containers. In this article, we will see how docker stores the docker images in some popular registries like Dockerhub and how to publish the Docker images to Docker Hub. By publishing the images to the docker hub and making it pu
    8 min read
    Docker Commit
    Docker is an open-source container management service and one of the most popular tools of DevOps which is being popular among the deployment team. Docker is mostly used in Agile-based projects which require continuous delivery of the software. The founder, Chief Technical Officer, and Chief Archite
    10 min read
    Docker - Using Image Tags
    Image tags are used to describe an image using simple labels and aliases. Tags can be the version of the project, features of the Image, or simply your name, pretty much anything that can describe the Image. It helps you manage the project's version and lets you keep track of the overall development
    7 min read
    Next.js Docker Images
    Using Next.js Docker images allows your app to deploy to multiple environments, and is more portable, isolated and scalable in dev and prod. Docker’s containerization makes app management super easy, you can move from one stage to another with performance.Before we get started, let’s cover the basic
    14 min read
    How to Use Local Docker Images With Minikube?
    Minikube is a software that helps in the quick setup of a single-node Kubernetes cluster. It supports a Virtual Machine (VM) that runs over a docker container and creates a Kubernetes environment. Now minikube itself acts as an isolated container environment apart from the local docker environment,
    7 min read

    Docker Containers

    Containerization using Docker
    Docker is the containerization platform that is used to package your application and all its dependencies together in the form of containers to make sure that your application works seamlessly in any environment which can be developed or tested or in production. Docker is a tool designed to make it
    9 min read
    Virtualisation with Docker Containers
    In a software-driven world where omnipresence and ease of deployment with minimum overheads are the major requirements, the cloud promptly takes its place in every picture. Containers are creating their mark in this vast expanse of cloud space with the world’s top technology and IT establishments re
    8 min read
    Docker - Docker Container for Node.js
    Node.js is an open-source, asynchronous event-driven JavaScript runtime that is used to run JavaScript applications. It is widely used for traditional websites and as API servers. At the same time, a Docker container is an isolated, deployable unit that packages an application along with its depende
    12 min read
    Docker - Remove All Containers and Images
    In Docker, if we have exited a container without stopping it, we need to manually stop it as it has not stopped on exit. Similarly, for images, we need to delete them from top to bottom as some containers or images might be dependent on the base images. We can download the base image at any time. So
    10 min read
    How to Push a Container Image to a Docker Repository?
    In this article we will look into how you can push a container image to a Docker Repository. We're going to use Docker Hub as a container registry, that we're going to push our Docker image to.  Follow the below steps to push container Image to Docker repository:Step 1: Create a Docker Account The f
    3 min read
    Docker - Container Linking
    Docker is a set of platforms as a service (PaaS) products that use the Operating system level visualization to deliver software in packages called containers.There are times during the development of our application when we need two containers to be able to communicate with each other. It might be p
    4 min read
    How to Manage Docker Containers?
    Before virtualization, the management of web servers and web applications was tedious and much less effective. Thanks to virtualization, this task has been made much easier. This was followed by containerization which took it a notch higher. For network engineers, learning the basics of virtualizati
    13 min read
    Mounting a Volume Inside Docker Container
    When you are working on a micro-service architecture using Docker containers, you create multiple Docker containers to create and test different components of your application. Now, some of those components might require sharing files and directories. If you copy the same files in all the containers
    10 min read
    Difference between Docker Image and Container
    Pre-requisite: Docker Docker builds images and runs containers by using the docker engine on the host machine. Docker containers consist of all the dependencies and software needed to run an application in different environments. What is Docker Image?The concept of Image and Container is like class
    5 min read
    Difference between Virtual Machines and Containers
    Virtual machines and Containers are two ways of deploying multiple, isolated services on a single platform. Virtual Machine:It runs on top of an emulating software called the hypervisor which sits between the hardware and the virtual machine. The hypervisor is the key to enabling virtualization. It
    2 min read
    How to Install Linux Packages Inside a Docker Container?
    Once you understand how to pull base Docker Images from the Docker registry, you can now simply pull OS distributions such as Ubuntu, CentOS, etc directly from the Docker hub. However, the OS Image that you have pulled simply contains a raw file system without any packages installed inside it. When
    2 min read
    Copying Files to and from Docker Containers
    While working on a Docker project, you might require copying files to and from Docker Containers and your Local Machine. Once you have built the Docker Image with a particular Docker build context, building it again and again just to add small files or folders inside the Container might be expensive
    9 min read
    How to Run MongoDB as a Docker Container?
    MongoDB is an open-source document-oriented database designed to store a large scale of data and allows you to work with that data very efficiently. It is categorized under the NoSQL (Not only SQL) database because the storage and retrieval of data in MongoDB are not in the form of tables.  In this
    4 min read
    Docker - Docker Container for Node.js
    Node.js is an open-source, asynchronous event-driven JavaScript runtime that is used to run JavaScript applications. It is widely used for traditional websites and as API servers. At the same time, a Docker container is an isolated, deployable unit that packages an application along with its depende
    12 min read
    Docker - Container for NGINX
    Docker is an open-source platform that enables developers to easily develop, ship, and run applications. It packages an application along with its dependencies in an isolated virtual container which usually runs on a Linux system and is quite light compared to a virtual machine. The reason is that a
    11 min read
    How to Provide the Static IP to a Docker Container?
    Docker is an open-source project that makes it easier to create, deploy and run applications. It provides a lightweight environment to run your applications.It is a tool that makes an isolated environment inside your computer. Think of Docker as your private room in your house. Living with your fami
    2 min read

    Docker Compose

    Docker Compose
    An open-source platform called Docker makes designing, shipping, and deploying applications simple. It runs an application in an isolated environment by compiling its dependencies into a so-called container. for additional information on Docker. In a normal case, several services, such as a database
    15+ min read
    Docker Compose Tool To Run aMulti Container Applications
    The article talks about how to run multi-container applications using a single command. Docker Compose is a tool for defining and running multi-container Docker applications. With Compose, you can configure a file (YAML file) to configure your docker containers. Then Once you configured the Yaml fil
    8 min read

    Docker Swarm

    Docker Swarm Mode
    Docker swarm is a container orchestration tool. Swarm Mode in Docker was introduced in version 1.12, enabling the ability to deploy multiple containers on multiple Docker hosts. For this Docker uses an overlay network for the service discovery and with a built-in load balancer for scaling the servic
    14 min read
    Docker Swarm vs Kubernetes
    Containers are brilliant at packaging and holding all application codes, dependencies, libraries, and necessary configurations in a way that you can run them anywhere easily. But the problem arises from the fact that containers themselves cannot do things like load balancing, provisioning hosts, dis
    10 min read

    Docker Networking

    Docker Networking
    Pre-requisite: Docker Docker Networking allows you to create a Network of Docker Containers managed by a master node called the manager. Containers inside the Docker Network can talk to each other by sharing packets of information. In this article, we will discuss some basic commands that would help
    5 min read
    Docker - Managing Ports
    Pre-requisites: Docker Docker is a set of platform-as-a-service products that use OS-level virtualization to deliver software in packages called containers. These containers may need to talk to each other or to services outside docker, for this we not only need to run the image but also expose the c
    4 min read
    Creating a Network in Docker and Connecting a Container to That Network
    Networks are created so that the devices which are inside that network can connect to each other and transfer of files can take place. In docker also we can create a network and can create a container and connect to the respective network and two containers that are connected to the same network can
    2 min read
    Connecting Two Docker Containers Over the Same Network
    Whenever we expose a container's port in docker, it creates a network path from the outside of that machine, through the networking layer, and enters that container. In this way, other containers can connect to it by going out to the host, turning around, and coming back in along that path.Docker of
    3 min read
    How to use Docker Default Bridge Networking?
    Docker allows you to create dedicated channels between multiple Docker Containers to create a network of Containers that can share files and other resources. This is called Docker Networking. You can create Docker Networks with various kinds of Network Drivers which include Bridge drivers, McVLAN dr
    7 min read
    Create your own secure Home Network using Pi-hole and Docker
    Pi-hole is a Linux based web application, which is used as a shield from the unwanted advertisement in your network and also block the internet tracking system. This is very simple to use and best for home and small office networks. This is totally free and open-source. It also allows you to manage
    3 min read

    Docker Registry

    What is Docker Registry?
    Docker Registry is a centralized storage and distributed system for collecting and managing the docker images. It provides both public and private repositories as per the choice whether to make the image accessible publicly or not. It is an essential component in the containerization workflow for st
    10 min read
    Docker - Using Public Repositories To Host Docker Images
    Docker is a software platform for creating isolated virtualized environments for building, deploying, and testing applications with ease. In this tutorial, we will learn how to host public repositories on docker hub which is a hosted repository service provided by Docker for finding and sharing cont
    10 min read
    Docker - Private Registries
    Pre-requisites: Docker, Docker HUB Docker registry is your own private repository where you can store your own Docker images and share them with others. Docker Registry is basically organized into Docker Repositories. Within the docker Repository, you can maintain specific versions of a Docker Image
    3 min read
    Creating a Private Repository and Push an Image to That Private Repository
    In this article, we show how to create a docker hub account and pull the image from the docker hub repository and push our image to the docker hub repository. As the docker hub is a public repository that can be accessed by anyone so one can create their own private repository to which they can push
    2 min read
    Docker - Using Public Repositories To Host Docker Images
    Docker is a software platform for creating isolated virtualized environments for building, deploying, and testing applications with ease. In this tutorial, we will learn how to host public repositories on docker hub which is a hosted repository service provided by Docker for finding and sharing cont
    10 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