Docker Commands with Examples

In this blog, I’ll talk about essential Docker Commands that you will be using frequently while you are working with Docker.

Docker Commands with Examples

docker --version

This command is used to get the currently installed version of docker docker-version.PNG docker pull

Usage: docker pull [image name]

This command is used to pull images . Docker looks for this image on our local system. When it can’t find the image, Docker downloads it from Docker Hub for us. docker-pull.PNG

docker run

Usage: docker run -it -d [image name]

This command is used to create a container from an image

docker-run.PNG

docker ps

This command is used to list the running containers

docker-c-list.PNG

docker ps -a

This command will show all the containers both stopped and running.

docker-ps-a.PNG

docker images

This command lists all the docker images.

image-list.PNG

docker rm

Usage: docker rm [container id]

This command is used to delete a stopped container. (First stop the container before delete it. Because running container cant be delete )

rm-c.PNG

docker rmi

Usage: docker rmi [image id]

This command is used to delete a image. remove-image.PNG

docker stop

Usage: docker stop [container id] or docker container stop [container id]

This command stops a running container.

stop-c.PNG

container-stop.PNG

docker build

Usage: docker build [path to docker file]

The docker build command builds Docker images from a Dockerfile

build.PNG