Wednesday, 10 July 2019

10 Docker Command Part-3 By Raj Gupta



1. This will create a container in which nginx web server will run in the background

[root@ip-172-31-38-174 ~]# docker container run -d nginx

2. This will give private ip and port of running container and by the help of this ip we can access the web server running on this container,

[root@ip-172-31-38-174 ~]# docker container inspect dd8442fd1087

Note:- 172.17.0.2 this ip is not accessible outside to access we need to do port mapping

3. This will give the logs of running container

[root@ip-172-31-38-174 ~]# docker container logs dd8442fd1087

4. This will give all the running process inside the container

[root@ip-172-31-38-174 ~]# docker container top dd8442fd1087

5. This will give how much cpu and memory are utilized by all running container

[root@ip-172-31-38-174 ~]# docker container stats           

6. This will do the port mapping whatever request come to port 3600 it will forward the request to port 80

[root@ip-172-31-38-174 ~]# docker container run -d -p 3600:80 --name raj nginx 

Now if give http://3.85.8.204:3600/( public ip of ec2 server) in  browser then it will forward the request to container private ip(172.17.0.3 this is not ec2 server private ip it is container private ip which are running on ec2) on port 80 and we are able to access the web container

To check port mapping and name of container run the below command
[root@ip-172-31-38-174 ~]# docker container ls

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES

b5e091c626b3        nginx               "nginx -g 'daemon of…"   4 minutes ago       Up 4 minutes        0.0.0.0:3600->80/tcp   raj

7. This will take you inside container to install any software inside the container

[root@ip-172-31-38-174 ~]# docker container exec -it b5e091c626b3 /bin/bash

root@b5e091c626b3:/#           -------Now install any software you want

8. This will rename the docker container name

[root@ip-172-31-38-174 ~]# docker container rename dd8442fd1087 aws

9. This will restart the container

[root@ip-172-31-38-174 ~]# docker container restart b5e091c626b3

10. This command will take the running container from background to front screen

[root@ip-172-31-38-174 ~]# docker container attach 74094d60f4b3

No comments:

Post a Comment