On this article, we are going to learn the basic Docker commands and operations that every admin should know. So, if you are new here, please go through the following articles to get a better idea about Docker and it’s installation process.
- Learn Docker From Scratch – Introduction
- How to install Docker CE on CentOS 7
- How to install the latest version of Docker on Ubuntu
Basic Docker Commands
1. docker version
This command is used to check the version of docker installed on your system.
Usage: docker --version
2. docker pull
Used to pull an image from the docker hub.
Usage: docker image pull <image_name> or docker pull <image_name>
3. docker image list
List all images on your system.
Usage: docker image list
4. docker run
Will create a container from the specified image and then run it.
Usage: docker container run -dit <image_name/image_id> or Usage: docker run -dit <image_name/image_id>
5. docker ps
Used to list the running containers.
Usage: docker ps
6. docker ps -a
Will show all the running and exited containers
Usage: docker ps -a
Here, you can see two centos containers listed. One is Up and running for the last 29 minutes while the other one is in Exited status.
7. docker exec
Used to execute a command on a particular docker container.
Usage: docker exec -it <container_id> <command_to_execute>
So, in the above example, we have actually logged in to the shell of our CentOS container.
8. docker stop
Used to stop a running container
Usage: docker stop <container-id>
You can then run “docker ps -a” to check the status of the container.
9. docker kill
Used to kill(stop immediately) a container.
Usage: docker kill <container-id>
10. docker start
Used to start a stopped container
Usage: docker start <container-id>
11. docker rm
Used to remove a stopped container.
Usage: docker container rm <container_id> or Usage: docker rm <container_id>
12. docker rmi
Used to remove/delete an image from local storage
Usage: docker rmi <image_id/image_name> or docker image rm <image_id/image_name>
That’s it. We will discuss more docker commands on the future posts. However, you can check out the complete list of docker commands in the official docker documentation link given below. If you have any questions, please leave a comment below.