1. docker --version
Usage: docker --version
This command is used to get the currently installed version of docker.
2. docker pull
Usage: docker pull <image name>
Eg: docker pull ubuntu
This command is used to pull an image or a repository from the docker registry (hub.docker.com)
3. docker run
Usage: docker run -it -d <image name>
Eg: docker run -it -d ubuntu
-i: -- interactive = keep STDIN open even if not attached
-t: --tty = Allocate a pseudo-TTY
-d: --detach = Run container in background and print container ID
This command is used to create a container from an Image
4. docker ps
Usage: docker ps
This command is used to display the running containers
5. docker ps -a
Usage: docker ps -a
-a: --all = show all containers
This command is used to show all running and exited containers
6. docker ps -l
Usage: docker ps -l
-l: --latest = show the latest created container (includes all states like exited/ running)
This command is used to show the latest created container
7. docker exec
Usage: docker exec -it <container id> bash
Eg: docker exec -it 29c10a7bf2ea bash
-i: -- interactive = keep STDIN open even if not attached
-t: --tty = Allocate a pseudo-TTY
8. docker stop
If we want to stop all the running containers at a time, then use the below command
Method 1:
Usage: docker container stop $(docker container ls -aq)
Method 2:
Usage: docker stop <container id>
Eg: docker stop 29c10a7bf2ea
This command is used to stop one or more running containers
9. docker commit
Usage: docker commit <container id> <username/imagename>
Eg: docker commit 29c10a7bf2ea krishnadasari610/ubuntu
This command is used to create new image of an edited container on the local system
Once we create a new image
10 docker login
Usage: docker login
1. If you are already logged into your docker hub account you will get the output like in the below image
2. If you are login for the first time, you will get the Username and then the password like in the below image provide the necessary details
11. docker logout
Usage: docker logout
This command is used to logout from the docker hub repository
12. docker push
Usage: docker push <username/ image name/id>
This command is used to push an image to the docker hub repository
Check in the Docker hub repository whether the same repository is available or not.
Login required : https://hub.docker.com/?ref=login
13. docker images
Usage: docker images
This command will list all the locally stored images
14. docker rm
If we want to remove all the stopped containers, then we can use the below command
Usage:docker rm $(docker ps -a -q)
Usage: docker rm <container id>
This command is used to delete a stopped container
1. If the container id is stopped then its status should be "Exited"
2. Remove the container and check the containers list
15 docker rmi
Method 1:
Usage: docker rmi <Image Name / Image ID>
This command is used to delete one or more images from the local storage
Method 2: Remove the all locally stored images
Usage: docker rmi $(docker image -a -q )
16. docker build
Usage: docker build </path/to/docker file>
Eg: docker build .
This command is used to build an image from a specified docker file.
Note: Open the terminal from the docker file location