Last Updated : 23 Jul, 2025
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 commandThis 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>Docker Pull
To give name of container
$ docker run --name <container_name> <image_name>
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>Docker PS
This command (by default) shows us a list of all the running containers. We can use various flags with it.
$ docker ps [options..]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 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:
$ docker rm {options} <container_name or ID>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 imagesDocker 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:
$ docker exec {options}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
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 LoginThe 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 PushOnce 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 StopYou 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_idStop 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 container3Docker 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_idDocker 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_idDocker 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:tagDocker Basic Command
Following are the some of the docker basic commands
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 CommandSuggested Quiz
6 Questions
What is the primary function of Docker?
Containerizing applications
Hosting web servers
Providing a virtualization platform
Managing databases
What command is used to pull an image from the Docker registry?
docker build
docker run
docker pull
docker exec
Which command is used to list all the running containers?
docker ps
docker rm
docker images
docker start
What command is used to stop a running container?
docker start
docker stop
docker rm
docker exec
Which command is used to create a new Docker image from a running container?
docker commit
docker build
docker pull
docker run
Which of the following commands can be used to list all Docker containers?
docker container ls
docker ps
docker container ls -a
docker ps -a
Explanation:
docker container ls
:docker ps
:docker container ls
. It also lists only the running containers, not stopped ones.docker container ls -a
:-a
flag displays all containers, including running, stopped, and exited ones.docker ps -a
:docker container ls -a
and displays all containers.Quiz Completed Successfully
Your Score : 2/6
Accuracy : 0%
Login to View Explanation
1/6 1/6 < Previous Next >RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4