10 Docker Commands You Need to Know

In this tutorial, We will delve into the fundamental Docker commands crucial for anyone working with this widely adopted containerization tool.
Docker has become a cornerstone for developers and DevOps engineers, providing a streamlined approach to constructing, transporting, and executing applications within containers. Its simplicity and efficiency make it an indispensable asset in application deployment and management. Whether you are a novice exploring Docker’s capabilities or a seasoned professional implementing it in production, understanding these essential commands is pivotal.
This article aims to highlight and explain the ten imperative Docker commands that will be integral to your routine tasks.

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
10 Docker Commands You Need to Know

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!

,

About HuuPV

My name is Huu. I love technology and especially Devops Skill such as Docker, vagrant, git so forth. I likes open-sources. so I created DevopsRoles.com site to share the knowledge that I have learned. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.