Most Useful Docker Commands

Share via:

Dear Readers,

In this article,we will see Most useful Docker Commands.

1 Install Docker Package yum install docker -y
2 Verify the docker package installed or not which docker
3 See the Version of Docker docker –version
4 Start the service of Docker service docker start
5 Verify the status of Docker service docker status
6 Verify the status of Docker docker info
7 see all images inside your machine docker images
8 See the running containers docker ps
9 see all the containers inside your machine docker ps -a
10 create a container from ubuntu image docker run -it ubuntu //bin/bash
11 see the OS information cat /etc/os-release
12 Search Jenkin image from online docker registry (Docker Hub) docker search jenkins
13 Download Jenkin image from online docker registry (Docker Hub) docker pull jenkins
14 create a container from ubuntu image along with container name docker run –name ktexperts-container -it ubuntu //bin/bash
15 Go inside the container docker start ktexperts-container docker attach ktexperts-container
16 Delete the container docker rm <container-name>
docker rm ktexperts-container
17 Stop the container docker stop <container-name>
docker stop ktexperts1-container
18 Delete multiple containers docker rm <container-1-name> <container-2-name>
docker rm ktexperts1-container ktexperts2-container
19 delete image docker rmi <image-name>
docker rmi ubuntu
20 Delete multiple images docker rmi <image1-name> <image-2-name>
docker rmi chef/chefdk centos jenkins
21 what you have done in container docker diff <container-name>
docker diff kt-container
22 Create image from container docker commit <container-name>
docker commit kt-container
23 Give name to the above image docker tag <imamge-id> <image-name>
docker tag 5d721a8b702e kt1-image
24 creating the image along with name docker commit <container-name> <image-name>
docker commit kt-container kt2-image
25 Create image from Dockerfile docker build -t <image-name> <path of docker file>
docker build -t kt2-image .
26 Share volume with another New Container docker run -it –name <new-container-name> –privileged=true –volumes-from <old-container-name> <image-name> //bin/bash
docker run -it –name kt-container-2 –privileged=true –volumes-from kt-container-1 ubuntu //bin/bash
27 Create a container along with volume by using Command Line docker run -it –name <container-name> -v /<volume-name> <image-name> //bin/bash
docker run -it –name kt-container-4 -v /ktexperts-volume ubuntu //bin/bash
28 Create a container along with volumes by using Command Line (host to container) docker run -it –name <container-name> -v /<path for host volume>:/<volume-name> –privileged=true <image-name> //bin/bash
docker run -it –name ktexperts-container -v /home/ec2-user:/ktexperts –privileged=true ubuntu //bin/bash
29 See the list of all details of the containers docker inspect <container-name>
docker inspect ktexperts-container
30 Create a Dominized Container with image and port mapping docker run -td –name <container-name> -p <port-number>:<port-number> <image-name>
docker run -td –name ktexperts-webserver -p 80:80 ubuntu
31 Install webserver package “apache2” in ubuntu apt-get install apache2 -y
32 Start apache2 service service apache2 start
33 See the status of apache2 service service apache2 status
34 Logging to Docker Hub Account docker login
35 Reserve space for the image in Docker Hub docker tag <image-name> <Docker-Hub-Account-ID>/<give-new-image-name>
docker tag ktexperts-image rameshktexperts/ktexperts-new-image
36 Push the image to Docker Hub docker push<Docker-Hub-Account-ID>/<give-reserverd-image-name>
docker push rameshktexperts/ktexperts-new-image
37 Pull image from Docker Hub docker pull <Docker-Hub-Account-ID>/<give-reserverd-image-name>
docker pull rameshktexperts/ktexperts-new-image
38 Create a Dockerfile vi Dockerfile
FROM centos
RUN echo “Welcome to our website :” > /tmp/kt-file
39 Create a Dockerfile vi Dockerfile
FROM centos
RUN echo “Welcome to our website :” > /tmp/kt-file
RUN echo “It a knowledge sharing platform”> /tmp/kt-file2
COPY kt-file1 /tmp
ADD kt-file2.tar.gz /tmp
40 Create a Dockerfile with volume vi Dockerfile
FROM ubuntu
VOLUME [“/ktexperts”]

Thank you for giving your valuable time to read the above information. Please click here to subscribe for further updates

KTEXPERTS is always active on below social media platforms.


Facebook :
LinkedIn :
Twitter :
YouTube :
Instagram :

Share via:
Note: Please test scripts in Non Prod before trying in Production.
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

Add Comment