In this tutorial, You need to use 10 Docker Commands You Need to Know.
- Docker is a popular tool for building, shipping, and running applications in containers.
- It offers a simple and efficient way to deploy and manage applications, making it an essential tool for developers and DevOps engineers. Whether you’re just getting started with Docker or are already using it in production, it’s important to know the basic commands that you’ll be using frequently.
- In this article, we’ll take a look at the top Docker commands that you need to know.
Table of Contents
10 Docker Commands
1. docker run
The docker run
the command is used to start a new container from an image. It is the most basic and commonly used Docker command. Here’s an example of how to use it:
docker run nginx

This command will download the latest Nginx image from the Docker Hub and start a new container from it. The container will be started in the foreground and you can see the logs as they are generated.
2. docker ps
The docker ps
the command is used to list the running containers on your system. It provides information such as the container ID, image name, and status. Here’s an example of how to use it:
docker ps
This command will display a list of all the running containers on your system. If you want to see all containers (including stopped containers), you can use the -a
option:
docker ps -a
This will display a list of all the containers on your system, regardless of their status.
3. docker stop
The docker stop
the command is used to stop a running container. It sends a SIGTERM
signal to the container, allowing it to gracefully shut down. Here’s an example of how to use it:
docker stop mycontainer
This command will stop the container with the name mycontainer
. If you want to forcefully stop a container, you can use the docker kill
command:
docker kill mycontainer
This will send a SIGKILL
signal to the container, which will immediately stop it. However, this may cause data loss or other issues if the container was not properly shut down.
4. docker rm
The docker rm command is used to remove a stopped container.
syntax
docker rm <container>
For example, to remove the container with the ID “xxx123“, you can use the command
docker rm xxx123
5. docker images
The docker images command is used to list the images available locally. This command will display a list of all the images that are currently available on your system.
6. docker rmi
The docker rmi command is used to remove a local image.
syntax
docker rmi <image>
For example, to remove the image with the name “myimage“, you can use the command.
docker rmi myimage
7. docker logs
The docker logs command is used to show the logs of a running container.
Syntax
docker logs <container>
For example, to show the logs of the container with the ID “xxx123“, you can use the command docker logs xxx123.
8. docker exec -it
The docker exec command is used to run a command inside a running container.
syntax
docker exec -it <container> <command>
For example, to run a bash shell inside the container with the ID “xxx123“, you can use the command
docker exec -it xxx123 bash
9. docker build -t
The docker build command is used to build a Docker image from a Dockerfile file.
syntax
docker build -t <image> <path>
For example, to build an image with the name “myimage” from a Dockerfile located in the current directory, you can use the command
docker build -t myimage .
10. docker-compose up
The docker-compose command is used to start containers defined in a Docker Compose file. This command will start all the containers defined in the Compose file.
Conclusion
These are the top Docker commands that you’ll use frequently when working with Docker. Mastering these commands will help you get started with Docker and make it easier to deploy and manage your applications. I hope will this your helpful. Thank you for reading the DevopsRoles page!