Docker Images Explained with Examples

List out docker images

Sudo docker images

search Ubuntu

Sudo docker search Ubuntu

##Search image

Sudo docker search busapp

##Pull the Ubuntu

Sudo docker pull Ubuntu

##Pull the Image

Sudo docker pull learnitguide/busapp:latest

##List out images

Sudo docker images

##run a container

Sudo docker run –d –it --name myhttpd httpd

##Check Container run or not

Sudo docker ps –a

##Container run different port

Sudo docker run –d –it --name myhttpd1 –p 81:80 httpd

Now put ip in browser with 81 port

##Check ip

Ip a

##Change port no

Sudo docker run –d –it –name myhttpd –p 82:80 httpd

Now put ip in browser with 82 port

##Inspect a image

Sudo docker inspect learnitguide/busapp:latest

##run a busapp

Sudo docker run –d –it –name busapp-dev –p 8001:8001 learnitguide/busapp

Now put ip in browser with 8001 port

##Check running acontainer

Sudo docker ps –a

##View the history

Sudo docker history httpd:latest

##Take a backup of container

Sudo docker save c6b84b685f35 >Ubuntu-bkp.tar

##View the file

Ls –lrt

##load a docker file

Sudo docker load –I Ubuntu-bkp.tar

Remove a container

Sudo docker rm container id/name

##Remove a image

Sudo docker rmi image id/name

##Delete all images

Sudo docker rmi $(sudo docker images –a –q)

##Load imgae from local image tar backup

Sudo docker load –I Ubuntu-bk.tar

##run a container from image

Sudo docker run –d –it –name ubuntu1ubuntu:latest /bin/sh

##Login a container

Sudo docker exec -it ubuntu1 /bin/bash

##Create a directory and file

Mkdir India

Touch dummy

##install namp

Apt-get update

Apt-get install namp

Apt-get install curl

##Commit a container

Sudo docker commit container id

##See the images

Sudo docker images

##Give a tag

Sudo docker commit container id customimage:2:1

##Run a image

Sudo docker run –d –it –name customubuntu customimage:2.1 /bin/sh

##Login a container

Sudo docker exec –it customubuntu /bin/sh

bash

Ls –lrt

See the two files

India and dummy

##login docker hub site

Sudo docker login

##push the images

Sudo docker push learnitguide/customimage:2.1

##Check current registry

Sudo docker info