chrisluiz16

Untitled

May 23rd, 2023
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 9.94 KB | None | 0 0
  1. #---------------------------------------------------- httpd image pull --------------------------------------------#
  2.  
  3.  
  4. [ec2-user@ip-172-31-41-59 ~]$ docker image ls
  5. REPOSITORY   TAG             IMAGE ID       CREATED       SIZE
  6. httpd        2-alpine3.18    d7544b312621   11 days ago   59.1MB
  7. httpd        2.4.57-alpine   d7544b312621   11 days ago   59.1MB
  8. httpd        alpine          d7544b312621   11 days ago   59.1MB
  9. httpd        2.4-bullseye    b4f91978e2cc   11 days ago   145MB
  10. httpd        2.4.57          b4f91978e2cc   11 days ago   145MB
  11. httpd        latest          b4f91978e2cc   11 days ago   145MB
  12.  
  13.  
  14.  
  15. #---------------------------------------------------- Image Inspection --------------------------------------------#
  16.  
  17.  
  18. [ec2-user@ip-172-31-41-59 ~]$ docker image inspect --format='{{json .Config.Cmd}}' httpd:alpine
  19. ["httpd-foreground"]
  20.  
  21. [ec2-user@ip-172-31-41-59 ~]$ docker image inspect --format='{{json .Config.Cmd}}' httpd
  22. ["httpd-foreground"]
  23.  
  24.  
  25. [ec2-user@ip-172-31-41-59 ~]$ docker image ls ubuntu
  26. REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
  27. ubuntu       18.04     97ba4bbc97fc   10 days ago   63.2MB
  28.  
  29.  
  30. [ec2-user@ip-172-31-41-59 ~]$ docker image inspect --format='{{json .Config.Cmd}}' ubuntu:18.04
  31. ["/bin/bash"]
  32.  
  33.  
  34.  
  35. #---------------------------------------------------- Container Creation --------------------------------------------#
  36.  
  37.  
  38.  
  39. [ec2-user@ip-172-31-41-59 ~]$ docker container run --name container1 -it ubuntu:18.04
  40. root@13a2dfb944f6:/#
  41. root@13a2dfb944f6:/#
  42. root@13a2dfb944f6:/#
  43. root@13a2dfb944f6:/#
  44.  
  45. [ec2-user@ip-172-31-41-59 ~]$ docker container run --name webserver1 -d httpd
  46. f801695a2a69c52f87553767cdb7f8d74b132c92d8af8fcc4ee537b812361bc0
  47.  
  48. [ec2-user@ip-172-31-41-59 ~]$ docker container inspect --format='{{range .NetworkSettings.Networks}}{{println .IPAddress}}{{end}}' webserver1
  49. 172.17.0.2
  50.  
  51. [ec2-user@ip-172-31-41-59 ~]$ curl http://172.17.0.2
  52. <html><body><h1>It works!</h1></body></html>
  53.  
  54.  
  55. [ec2-user@ip-172-31-41-59 ~]$ docker container run -p 8080:80 -d --name webserver2 httpd
  56. 2b81735db75bbe62732b4a3a8295e342ec32dee20b4bdc97e3ef25f5432e0b20
  57.  
  58. [ec2-user@ip-172-31-41-59 ~]$ docker container inspect --format='{{range .NetworkSettings.Networks}}{{println .IPAddress}}{{end}}' webserver2
  59. 172.17.0.3
  60.  
  61. [ec2-user@ip-172-31-41-59 ~]$ curl http://65.0.30.0:8080
  62. <html><body><h1>It works!</h1></body></html>
  63.  
  64.  
  65.  
  66. #---------------------------------------------------- Docker exec --------------------------------------------#
  67.  
  68.  
  69. [ec2-user@ip-172-31-41-59 ~]$ docker exec webserver1 date
  70. Tue May 23 09:11:58 UTC 2023
  71. [ec2-user@ip-172-31-41-59 ~]$
  72. [ec2-user@ip-172-31-41-59 ~]$ docker exec webserver1 ifconfig
  73. OCI runtime exec failed: exec failed: unable to start container process: exec: "ifconfig": executable file not found in $PATH: unknown
  74. [ec2-user@ip-172-31-41-59 ~]$
  75. [ec2-user@ip-172-31-41-59 ~]$
  76. [ec2-user@ip-172-31-41-59 ~]$ docker exec webserver1 ping
  77. OCI runtime exec failed: exec failed: unable to start container process: exec: "ping": executable file not found in $PATH: unknown
  78.  
  79.  
  80. [ec2-user@ip-172-31-41-59 ~]$ docker container exec -it webserver2 bash
  81. root@2b81735db75b:/usr/local/apache2#
  82. root@2b81735db75b:/usr/local/apache2# apt update && apt install net-tools vim procps -y &> /dev/null
  83. Get:1 http://deb.debian.org/debian bullseye InRelease [116 kB]
  84. Get:2 http://deb.debian.org/debian-security bullseye-security InRelease [48.4 kB]
  85. Get:3 http://deb.debian.org/debian bullseye-updates InRelease [44.1 kB]
  86. Get:4 http://deb.debian.org/debian bullseye/main amd64 Packages [8183 kB]
  87. Get:5 http://deb.debian.org/debian-security bullseye-security/main amd64 Packages [243 kB]
  88. Get:6 http://deb.debian.org/debian bullseye-updates/main amd64 Packages [14.6 kB]
  89. Fetched 8649 kB in 2s (5429 kB/s)
  90. Reading package lists... Done
  91. Building dependency tree... Done
  92. Reading state information... Done
  93. All packages are up to date.
  94.  
  95. eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
  96.         inet 172.17.0.3  netmask 255.255.0.0  broadcast 172.17.255.255
  97.         ether 02:42:ac:11:00:03  txqueuelen 0  (Ethernet)
  98.         RX packets 731  bytes 18132004 (17.2 MiB)
  99.         RX errors 0  dropped 0  overruns 0  frame 0
  100.         TX packets 386  bytes 30025 (29.3 KiB)
  101.         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  102.  
  103. lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
  104.         inet 127.0.0.1  netmask 255.0.0.0
  105.         loop  txqueuelen 1000  (Local Loopback)
  106.         RX packets 0  bytes 0 (0.0 B)
  107.         RX errors 0  dropped 0  overruns 0  frame 0
  108.         TX packets 0  bytes 0 (0.0 B)
  109.         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  110.        
  111. root@2b81735db75b:/usr/local/apache2# echo "<h1><center>I'm in a devops class</h1></center>" > /usr/local/apache2/htdocs
  112. /index.html
  113. root@2b81735db75b:/usr/local/apache2# ps aux
  114. USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
  115. root           1  0.0  0.4   6000  4448 ?        Ss   09:06   0:00 httpd -DFOREGROUND
  116. www-data       8  0.0  0.3 807220  3260 ?        Sl   09:06   0:00 httpd -DFOREGROUND
  117. www-data       9  0.0  0.3 807220  3260 ?        Sl   09:06   0:00 httpd -DFOREGROUND
  118. www-data      10  0.0  0.3 807284  3692 ?        Sl   09:06   0:00 httpd -DFOREGROUND
  119. www-data      92  0.0  0.3 807284  3696 ?        Sl   09:08   0:00 httpd -DFOREGROUND
  120. root         120  0.0  0.3   4152  3248 pts/0    Ss   09:22   0:00 bash
  121. root         573  0.0  0.2   6756  2816 pts/0    R+   09:24   0:00 ps aux
  122. [ec2-user@ip-172-31-41-59 ~]$ curl http://65.0.30.0:8080
  123. <h1><center>I'm in a devops class</h1></center>
  124.  
  125.  
  126. #---------------------------------------------------- Deleting the container --------------------------------------------#
  127.  
  128. [ec2-user@ip-172-31-41-59 ~]$ docker container ls -a
  129. CONTAINER ID   IMAGE          COMMAND              CREATED             STATUS                         PORTS                                   NAMES
  130. 2b81735db75b   httpd          "httpd-foreground"   20 minutes ago      Up 20 minutes                  0.0.0.0:8080->80/tcp, :::8080->80/tcp   webserver2
  131. f801695a2a69   httpd          "httpd-foreground"   39 minutes ago      Up 39 minutes                  80/tcp                                  webserver1
  132. 13a2dfb944f6   ubuntu:18.04   "/bin/bash"          About an hour ago   Exited (0) About an hour ago    
  133.  
  134. [ec2-user@ip-172-31-41-59 ~]$ docker container stop webserver1
  135. webserver1
  136. [ec2-user@ip-172-31-41-59 ~]$ docker container stop webserver2
  137. webserver2
  138. [ec2-user@ip-172-31-41-59 ~]$ docker container rm webserver2
  139. webserver2
  140. [ec2-user@ip-172-31-41-59 ~]$ docker container rm webserver1
  141. webserver1
  142.  
  143. [ec2-user@ip-172-31-41-59 ~]$ docker container rm container1
  144. container1
  145. [ec2-user@ip-172-31-41-59 ~]$
  146. [ec2-user@ip-172-31-41-59 ~]$ docker container ls -a
  147. CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
  148. [ec2-user@ip-172-31-41-59 ~]$
  149.  
  150.  
  151. #---------------------------------------------------- Bind mounting --------------------------------------------#
  152.  
  153. [ec2-user@ip-172-31-41-59 ~]$ docker container run --name webserver1 -p 8080:80 -d -v /home/ec2-user/site1:/usr/local/apache2/htdocs httpd
  154. c4cc32ad018c95a4c819edf5fcc1f0d61bb1800118e9468bb2d9c1ad1f9fd829
  155. [ec2-user@ip-172-31-41-59 ~]$
  156. [ec2-user@ip-172-31-41-59 ~]$[ec2-user@ip-172-31-41-59 ~]$ docker container run --name webserver2 -p 8081:80 -d -v /home/ec2-user/site2:/usr/local/apache2/htdocs httpd
  157. f5bf2c6936343d41d3db6ea07385c7ebcf16187fb6e3f0a4244c71bd7d20a5d3
  158. [ec2-user@ip-172-31-41-59 ~]$
  159. [ec2-user@ip-172-31-41-59 ~]$
  160. ec2-user@ip-172-31-41-59 ~]$ docker container ls
  161. CONTAINER ID   IMAGE     COMMAND              CREATED              STATUS              PORTS                                   NAMES
  162. f5bf2c693634   httpd     "httpd-foreground"   About a minute ago   Up About a minute   0.0.0.0:8081->80/tcp, :::8081->80/tcp   webserver2
  163. c4cc32ad018c   httpd     "httpd-foreground"   3 minutes ago        Up 3 minutes        0.0.0.0:8080->80/tcp, :::8080->80/tcp   webserver1
  164. [ec2-user@ip-172-31-41-59 ~]$
  165.  
  166.  
  167. #---------------------------------------------------- Nginx doc root --------------------------------------------#
  168.  
  169. [ec2-user@ip-172-31-41-59 ~]$ docker image pull nginx:latest
  170. latest: Pulling from library/nginx
  171. f03b40093957: Pull complete
  172. 0972072e0e8a: Pull complete
  173. a85095acb896: Pull complete
  174. d24b987aa74e: Pull complete
  175. 6c1a86118ade: Pull complete
  176. 9989f7b33228: Pull complete
  177. Digest: sha256:f5747a42e3adcb3168049d63278d7251d91185bb5111d2563d58729a5c9179b0
  178. Status: Downloaded newer image for nginx:latest
  179. docker.io/library/nginx:latest
  180. [ec2-user@ip-172-31-41-59 ~]$
  181. [ec2-user@ip-172-31-41-59 ~]$ docker image ls nginx:latest
  182. REPOSITORY   TAG       IMAGE ID       CREATED          SIZE
  183. nginx        latest    a7be6198544f   52 minutes ago   142MB
  184. [ec2-user@ip-172-31-41-59 ~]$
  185. [ec2-user@ip-172-31-41-59 ~]$ docker image inspect --format='{{json .Config.Cmd}}' nginx
  186. ["nginx","-g","daemon off;"]
  187. [ec2-user@ip-172-31-41-59 ~]$ docker container run --name webserver3 -p 8082:80 -d -v /home/ec2-user/site3:/usr/share/nginx/html nginx
  188. ca7dbbd4987d80775b5646ecffb2ed078afa3c1f77d373ac3f2c21d70ff7864b
  189. [ec2-user@ip-172-31-41-59 ~]$ docker container run --name webserver4 -p 8083:80 -d -v /home/ec2-user/site4:/usr/share/nginx/html nginx
  190. 97b2e89aa2e9f21fe9f9e94301d2c3273c6cec377571813694b8060bd22d0209
  191. [ec2-user@ip-172-31-41-59 ~]$ docker container ls -a
  192. CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS          PORTS                                   NAMES
  193. 97b2e89aa2e9   nginx     "/docker-entrypoint.…"   2 minutes ago    Up 2 minutes    0.0.0.0:8083->80/tcp, :::8083->80/tcp   webserver4
  194. ca7dbbd4987d   nginx     "/docker-entrypoint.…"   3 minutes ago    Up 3 minutes    0.0.0.0:8082->80/tcp, :::8082->80/tcp   webserver3
  195. f5bf2c693634   httpd     "httpd-foreground"       47 minutes ago   Up 47 minutes   0.0.0.0:8081->80/tcp, :::8081->80/tcp   webserver2
  196. c4cc32ad018c   httpd     "httpd-foreground"       49 minutes ago   Up 49 minutes   0.0.0.0:8080->80/tcp, :::8080->80/tcp   webserver1
Advertisement
Add Comment
Please, Sign In to add comment