Basic Docker CLI Commands
Hi, this article is for beginners in docker to get quickly acquainted with the basic docker commands once they have installed docker. Let’s begin
docker -v
This command will return the current version of docker installed on your computer. For a more detailed output, use the command docker version .
docker build -t imageName:tagv1 .
Assuming you have opened the terminal in the same folder as your dockerfile, this command will build an image from the dockerfile and name it as imageName and tag it as tagv1. If you are not in the folder containing the dockerfile, then you will have to mention the path of your dockerfile instead of the . used in the command.
docker images
This command will list all the images that are present locally on your computer.
docker run imageName
Get Ravi’s stories in your inbox
Join Medium for free to get updates from this writer.
This command will look for an image imageName on your computer first and if it’s not available, will look into the docker hub and fetch it. Once fetched, it will store the image on your computer and start a container with a random name. If you want to give a custom name to your container, add name flag to the command followed with a container name and image name. Example: docker run --name MyCustomContainer hello-world
docker stop MyCustomContainer
This command will stop the running container MyCustomContainer . You can also use the container id instead of the container name. To start the container again, just use docket start MyCustomContainer
docker ps
This command will list all the running containers. If you wish to see all the containers present locally on your computer, just add the --all flag to the command. Example: docker ps --all
docker rmi imageName
This command will delete the image imageName . If you wish to see all the images present on your computer locally, use docker images to list them.
docker rm containerName
This command will removed the container containerName if it is stopped already.
We shall learn a few advanced Docker CLI Commands in our next article. Thank you.






