Monday, November 20, 2023

Docker 6

 Let us revise the previous sessions once again. 


root@ip-172-31-15-245:~# docker images

REPOSITORY    TAG       IMAGE ID       CREATED        SIZE

nginx         latest    c20060033e06   2 weeks ago    187MB

ubuntu        18.04     f9a80a55f492   5 months ago   63.2MB

hello-world   latest    9c7a54a9a43c   6 months ago   13.3kB

root@ip-172-31-15-245:~# docker pull alpine

Using default tag: latest

latest: Pulling from library/alpine

96526aa774ef: Pull complete

Digest: sha256:eece025e432126ce23f223450a0326fbebde39cdf496a85d8c016293fc851978

Status: Downloaded newer image for alpine:latest

docker.io/library/alpine:latest

root@ip-172-31-15-245:~# docker images

REPOSITORY    TAG       IMAGE ID       CREATED        SIZE

nginx         latest    c20060033e06   2 weeks ago    187MB

alpine        latest    8ca4688f4f35   7 weeks ago    7.34MB

ubuntu        18.04     f9a80a55f492   5 months ago   63.2MB

hello-world   latest    9c7a54a9a43c   6 months ago   13.3kB

root@ip-172-31-15-245:~#


























To check what all the containers are running, then we use the below command

docker ps or docker container ls
docker ps -a







Assume that in case if i want to run the container busy box. then i go with the below command


root@ip-172-31-15-245:~# docker run busybox:latest
root@ip-172-31-15-245:~#













In the above screenshot, we can see that we have not assign any names to it. But we can assign own name by using the below command

 docker run --name con1 busybox:latest sh









From ,  the above screen shot you can see that i have defined the name as con1.


If you want to stop then you can use the below command


root@ip-172-31-15-245:~# docker stop con2
con2


Difference between pull and run and run command








When we run single command, it will check if that image is available or not locally.  If not available it will go and pull the image and then download and run.









 docker run -dit --name test123 ubunto:18.04, to give name  you need to run this command.









This, time i am not going to using the pull command. I am going to use the Run Command.


I am going to Run the different Image that is nginx.

docker run -idt --name abc123 -p 80:80 nginx-->If the image is not available
then it goes and pulls that image. 
If available locally, then it wont pull that image















If we want to stop any one of the container, then i can go with the below command










docker stop test123

If i go with docker info command

Total no of containers created stopped and running 
































root@ip-172-31-15-245:~# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS          PORTS                               NAMES
6466490db8e3   nginx     "/docker-entrypoint.…"   13 minutes ago   Up 13 minutes   0.0.0.0:80->80/tcp, :::80->80/tcp   abc123
root@ip-172-31-15-245:~#


Here, you can see the port no is 80

Now, i want to run the above container outside using port Number.

Get the ip address by running the below command

root@ip-172-31-15-245:~# hostname -i


Now, we need to login into the AWS Account, which we created , and browse with the public ip address

In the AWS Account, you can see the below screen






















Never Expose private IPto others, than people might krack and hack it

Now click on the security Group Link as shown below














Now, click on the Edit the Inbound Rules























Go at the bottom and add the new port Number












Now, browse the url with the public address and give the port name as 80 to it.






Now, i am going to stop that with the container id by using the below command

docker stop 6466490db8e3







Now, if i go and browse the nginx home page. 

I will get an error page saying that this site cant be reached. Because that is stop you wont be able o browse it
















Now, i am going to start it again by using the below command



root@ip-172-31-15-245:~# docker start abc123
abc123











Now, again you browse the nginx page, you will be able to load it












Now, i want to check the memory of the container. For that we have a command call as 

docker stats

You can give the container id or name 
docker stats abc123 
or
docker stats containerid













Once we run docker stats cmd, we can see the cpu usage, memory and other things

 We can also restart the container by using the below command

docker restart container id or name


root@ip-172-31-15-245:~# docker restart abc123
abc123
root@ip-172-31-15-245:~#


To remove the container we basically use linux cmd that is 
docker rm name or container id

First we need to stop it before deleting it. 








To remove image use the below command 
docker rmi name or id




Now, i want to go to the folder path. 
use the below cmdls will list out all the folder inside that folder







cat is the linux command used to open the file. Now, I am going to open the repostiores.json file










 











No comments:

Post a Comment

Thank you for visiting my blog

Kubernetes

Prerequisites We assume anyone who wants to understand Kubernetes should have an understating of how the Docker works, how the Docker images...