Thursday 14 December 2017

Docker Commands Practice

Docker commands:
1.       Want to check docker version use below command.
$ docker –v    (or)   $ docker --version
2.       Check complete docker information use below commands.
$ docker info
3.       Check what are all the option can we use in docker use below command.
$ docker
4.       List out the docker images use below command.
$ docker images
5.       If you want to search any docker images use below command.
$ docker search [option]
Ex: docker search Ubuntu
6.       If you want to run docker images use below command.
Note: if don’t have image locally its download first and then run automatically.
$ docker run --name  <container-name>   <image-name >
$ docker run -t  --name  <container-name>   <image-name >
$ docker run -d  -p 8181:8080 --name myapp pavithriya/webapp:v1
7.       If we want to download any docker image from docker hub or docker registry we need to use below command.
$ docker pull  <image name>
Ex: docker pull  tutum/hello-world
$ docker run –p  80 –name hello tutum/hello-world
Note: if we want check outside access port on the running container port use below command.
$ sudo docker port d35bf1374e88 80
$ docker run –p  1234:80 –name hello tutum/hello-world
Note: if we didn’t mention label (version) it will download latest version of the image.
8.       if we want to check the running docker containers use below command.
$ docker ps
9.       if we want to check running and stopping containers use below command.
$ docker ps –a
10.   if want to remove the container name use below command.
$ docker rm <containername>
11.   remove the docker images from the list.
$ docker rmi <image-name>
12.   check oly docker container ID’s use below command.
  $ docker ps –q
13.   to check latest running docker container use below command.
$ docker ps –l

14.   to kill running docker container use below command.
$ docker kill <container id>
15.   to stop the running container use below command.
$ docker stop <container id>

Diff b/w kill and stop : Both will stop the running container difference is stop will take 10 sec of time to stop the container(first it will send the signal then its stopped )kill won’t send any signal it will stop immediately.

16.   To run the stopped container use below command.
$ docker ps -a
$ docker  start <container id>
17.   If we want to check the logs of back round running container use below command.
$ docker ps -a
$ docker logs <container id>
$ docker logs 35nfdfw453  (or use first three characters of container id also ex: $ docker logs 35n )
If we want to check the follow up logs of running container use below command
$ docker logs  - -follow  - -tail 1 <container ID>
18.   If want to login any docker registry use below command. For example I want to login docker hub(it’s a public repository ).
$ docker login
 Enter username and password of docker hub.
19.   Build a custom docker image use below command.
$docker build –it ybmsr/hello:v1 .
Without cache
$dcoker build - -no-cache –t ybmsr/hello:v1 .
20.   Push docker image to docker hub or any repository use below command.
$ docker push ybmsr/hello:v1
21.   To check running docker container information use below command.
$ docker inspect <container ID>