Menu Close

List Of Frequently Used Docker Commands

In this article we are going to discuss List Of Frequently Used Docker Commands. We will see what are the list of commonly used commands in docker. These are the commands which are really useful while working on any project. Hope this will be useful. Please read my previous blog post of Create An Amazon AWS Free Tier Account.

Docker Commands

1) To list out the available commands in the installed docker version:1

docker --help

2) To check the information and options about the particular command:

Syntax : docker <command_name> –help1

docker run --help

3) To get the currently installed version of docker:1

docker –-version

4) To login to the local registry or docker hub repository:

Syntax : docker login –username=<user_name> –password=<password>1

docker login --username=testuser --password=password

5) To list out the all locally stored docker images:1

docker images ls

6) To pull an image from the docker repository (https://hub.docker.com/):

Syntax : docker pull <image_name:version>1

docker pull python

7) To push an image to the docker repository:

Syntax : docker push <image_name:version>1

docker push testimage:1.0

8) To build an image from the DockerFile in the current directory and tag the image:

Syntax : docker build <DockerFile_path> -t <image_name:version>1

docker build . -t testimage:1.0

9) To delete an image from the local image store:

Syntax : docker image rmi <image_name:version>1

docker image rmi testimage:1.0

10) To retag the local image with a new image name and tag:

Syntax : docker tag <image_name:version> <new_image_name:new_version>1

docker tag testimage:1.0 myimage:2.0

11) To display the history of images:

Syntax : docker history <image_name>1

docker history testimage

12) To search the Docker Hub for images:

Syntax : docker search <search_term>1

docker search dotnet

13) To create a container from an image:

Syntax : docker run -name <container_name> -it -d <image_name:version>1

docker run testcontainer -it -d testimage:1.0

14) To list out the all running containers:1

docker ps  (or) docker container ls

15) To list out the both all running and exited containers:1

docker ps -a

16) To run the stopped container:

Syntax : docker start <container_name or container_id>1

docker start testcontainer

17) To stop one or more running containers:

Syntax : docker stop <container_name or container_id>1

docker stop testcontainer
docker stop testcontainer1 testcontainer2

18) To kill the container. If the container is in a running state then it will stop and kill the container:

Syntax : docker kill <container_name or container_id>1

docker kill testcontainer

19) To remove one or more stopped containers:

Syntax : docker rm <container_name or container_id>1

docker rm testcontainer
docker rm testcontainer1 testcontainer2

20) To delete all running and stopped containers (force stop):1

docker container rm -f $(docker ps -aq)

21) To remove all stopped containers:1

docker container prune

22) To restart one or more containers:

Syntax : docker restart <container_name or container_id>1

docker restart testcontainer
docker restart testcontainer1 testcontainer2

23) To print the last ‘N’ lines of a container’s log:

Syntax : docker container logs –tail <no_of_lines> <container_name or container_id>1

docker container logs --tail 1000 testcontainer

24) To list port mappings of the container:

Syntax :  docker port <container_name or container_id>1

docker port testcontainer

25) To create a new image from edited container on the local system:

Syntax : docker commit <container_name or container_id> <image_name:version>1

docker commit testcontainer testimage:2.0

26) To access the running container which means run a command in the running container:

Syntax : docker exec -it <container_name or container_id> bash1

docker exec -it testcontainer bash

27) To create a new volume that containers can consume and store data in it:

Syntax : docker volume create <volume_name>1

docker volume create testvolume

28) To remove one or more volumes:

Syntax : docker volume rm <volume_name>1

docker volume rm testvolume

29) To copy files/folders between a container and the local file system:

Syntax : docker cp <src> <dest>1

docker cp index.html testcontainer:/index.html
docker cp testcontainer:/index.html index.html

30) To get the low-level information on Docker objects:

Syntax : docker inspect <object_name or id>1

docker inspect testcontainer

DockerCopy

31) To display system-wide information:1

docker info

32) To lists the details of all the networks in the cluster:1

docker network ls

33) To logging out from dockerhub:1

docker logout

Conclusion

Leave behind your valuable queries and suggestions in the comment section below. Also, if you think this article helps you, do not forget to share this with your developer community. Happy Coding 🙂

Jayant Tripathy
Coder, Blogger, YouTuber

A passionate developer keep focus on learning and working on new technology.

Leave a Reply

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