chrisluiz16

Day 5

May 24th, 2023
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 8.55 KB | None | 0 0
  1. #---------------------------------------------------- Creating New Directory --------------------------------------------#
  2.  
  3.  
  4. [ec2-user@ip-172-31-41-59 my-project]$ mkdir public_html
  5. [ec2-user@ip-172-31-41-59 my-project]$ touch public_html/{home.html,index.html,about.html}
  6. [ec2-user@ip-172-31-41-59 my-project]$ ls public_html/
  7. about.html  home.html  index.html
  8. [ec2-user@ip-172-31-41-59 my-project]$ echo "<h1><center>This is home.html page</h1></center>" > public_html/home.html
  9. [ec2-user@ip-172-31-41-59 my-project]$ echo "<h1><center>This is index.html page</h1></center>" > public_html/index.html
  10. [ec2-user@ip-172-31-41-59 my-project]$ echo "<h1><center>This is about.html page</h1></center>" > public_html/about.html
  11.  
  12.  
  13. #---------------------------------------------------- Alpine image --------------------------------------------#
  14.  
  15. [ec2-user@ip-172-31-41-59 my-project]$ docker image pull httpd:alpine
  16. alpine: Pulling from library/httpd
  17. 8a49fdb3b6a5: Pull complete
  18. beb66a906b34: Pull complete
  19. 01924573e8db: Pull complete
  20. 255f194b76b3: Pull complete
  21. 0f48f8ea2bc9: Pull complete
  22. 390cbd08c8ae: Pull complete
  23. Digest: sha256:3e25d419bf180122f5f9af5cf2180709d8234320ff25514a61f5d1bc3cf46394
  24. Status: Downloaded newer image for httpd:alpine
  25. docker.io/library/httpd:alpine
  26. [ec2-user@ip-172-31-41-59 my-project]$ docker image ls
  27. REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
  28. httpd        alpine    d7544b312621   12 days ago   59.1MB
  29. [ec2-user@ip-172-31-41-59 my-project]$ docker container run \
  30. > --name webserver \
  31. > -d \
  32. > -p 80:80 \
  33. > -v $(pwd)/public_html/:/usr/local/apache2/htdocs \
  34. > httpd:alpine
  35. d77eacee9328bf29dea44998d530a545c2dd4b35d57a06c941fcbc87abedff68
  36. [ec2-user@ip-172-31-41-59 my-project]$ curl http://ec2-15-206-73-205.ap-south-1.compute.amazonaws.com
  37. <h1><center>This is index.html page</h1></center>
  38. [ec2-user@ip-172-31-41-59 my-project]$ docker container exec webserver ls -l /usr/local/apache2/htdocs
  39. total 12
  40. -rw-r--r--    1 1000     1000            50 May 24 07:39 about.html
  41. -rw-r--r--    1 1000     1000            49 May 24 07:38 home.html
  42. -rw-r--r--    1 1000     1000            50 May 24 07:38 index.html
  43. [ec2-user@ip-172-31-41-59 my-project]$
  44. [ec2-user@ip-172-31-41-59 my-project]$
  45. [ec2-user@ip-172-31-41-59 my-project]$
  46. [ec2-user@ip-172-31-41-59 my-project]$ docker container logs webserver
  47. 103.158.218.18 - - [24/May/2023:07:50:29 +0000] "GET / HTTP/1.1" 304 -
  48. 103.158.218.18 - - [24/May/2023:07:50:29 +0000] "GET / HTTP/1.1" 304 -
  49. [ec2-user@ip-172-31-41-59 my-project]$
  50. [ec2-user@ip-172-31-41-59 my-project]$
  51. [ec2-user@ip-172-31-41-59 my-project]$ docker container logs -f webserver
  52. 103.158.218.18 - - [24/May/2023:07:56:10 +0000] "-" 408 -
  53. 103.158.218.18 - - [24/May/2023:07:59:08 +0000] "GET / HTTP/1.1" 304 -
  54. 103.158.218.18 - - [24/May/2023:08:00:00 +0000] "-" 408 -
  55.  
  56.  
  57. #---------------------------------------------------- DocIndex change --------------------------------------------#
  58.  
  59. [ec2-user@ip-172-31-41-59 my-project]$ docker container exec -it webserver sh
  60. /usr/local/apache2 #
  61. /usr/local/apache2 #
  62. /usr/local/apache2 # apk add vim
  63. /usr/local/apache2 # grep DirectoryIndex conf/httpd.conf
  64. /usr/local/apache2 #
  65. # DirectoryIndex: sets the file that Apache will serve if a directory
  66.     DirectoryIndex home.html index.html about.html
  67.    
  68. [ec2-user@ip-172-31-41-59 my-project]$ curl http://ec2-15-206-73-205.ap-south-1.compute.amazonaws.com
  69. <h1><center>This is index.html page</h1></center>
  70. [ec2-user@ip-172-31-41-59 my-project]$
  71. [ec2-user@ip-172-31-41-59 my-project]$ docker container restart webserver
  72. webserver
  73. [ec2-user@ip-172-31-41-59 my-project]$
  74. [ec2-user@ip-172-31-41-59 my-project]$ curl http://ec2-15-206-73-205.ap-south-1.compute.amazonaws.com
  75. <h1><center>This is home.html page</h1></center>
  76.  
  77.  
  78.  
  79. #---------------------------------------------------- Copying file to local system --------------------------------------------#
  80.  
  81. [ec2-user@ip-172-31-41-59 my-project]$ docker container cp webserver:/usr/local/apache2/conf/httpd.conf .
  82. [ec2-user@ip-172-31-41-59 my-project]$
  83. [ec2-user@ip-172-31-41-59 my-project]$
  84. [ec2-user@ip-172-31-41-59 my-project]$ ll
  85. total 24
  86. -rw-r--r--. 1 ec2-user ec2-user 20848 May 24 08:06 httpd.conf
  87. drwxr-xr-x. 2 ec2-user ec2-user    59 May 24 07:34 public_html
  88. [ec2-user@ip-172-31-41-59 my-project]$
  89. [ec2-user@ip-172-31-41-59 my-project]$
  90. [ec2-user@ip-172-31-41-59 my-project]$ docker container stop webserver
  91. webserver
  92. [ec2-user@ip-172-31-41-59 my-project]$ docker container rm webserver
  93. webserver
  94. [ec2-user@ip-172-31-41-59 my-project]$ docker container ls -a
  95. CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
  96.  
  97.  
  98.  
  99. #---------------------------------------------------- Creating a new container --------------------------------------------#
  100.  
  101.  
  102. [ec2-user@ip-172-31-41-59 my-project]$ docker container run \
  103. > --name webserver \
  104. > -d \
  105. > -p 80:80 \
  106. > -v $(pwd)/httpd.conf:/usr/local/apache2/conf/httpd.conf \
  107. > -v $(pwd)/public_html/:/usr/local/apache2/htdocs/ \
  108. > httpd:alpine
  109. 27188f1cc86f3c1fd59abdd0b6b78631cc7374bc89ca009ab8bf349c1d78c0c2
  110. [ec2-user@ip-172-31-41-59 my-project]$
  111. [ec2-user@ip-172-31-41-59 my-project]$ grep DirectoryIndex httpd.conf
  112. # DirectoryIndex: sets the file that Apache will serve if a directory
  113.     DirectoryIndex about.html index.html home.html
  114.     [ec2-user@ip-172-31-41-59 my-project]$
  115. [ec2-user@ip-172-31-41-59 my-project]$ docker container restart webserver
  116. webserver
  117. [ec2-user@ip-172-31-41-59 my-project]$
  118. [ec2-user@ip-172-31-41-59 my-project]$ curl http://ec2-15-206-73-205.ap-south-1.compute.amazonaws.com
  119. <h1><center>This is about.html page</h1></center>
  120. [ec2-user@ip-172-31-41-59 my-project]$
  121. [ec2-user@ip-172-31-41-59 my-project]$ echo "<h1><center>This is about.html updated page</h1></center>" > public_html/about.html
  122. [ec2-user@ip-172-31-41-59 my-project]$
  123. [ec2-user@ip-172-31-41-59 my-project]$ curl http://ec2-15-206-73-205.ap-south-1.compute.amazonaws.com
  124. <h1><center>This is about.html updated page</h1></center>
  125. [ec2-user@ip-172-31-41-59 my-project]$
  126.  
  127.  
  128.  
  129. #---------------------------------------------------- Docker Image Creation --------------------------------------------#
  130.  
  131.  
  132. [ec2-user@ip-172-31-41-59 my-project]$ docker container stop webserver
  133. webserver
  134. [ec2-user@ip-172-31-41-59 my-project]$
  135. [ec2-user@ip-172-31-41-59 my-project]$ docker container rm webserver
  136. webserver
  137. [ec2-user@ip-172-31-41-59 my-project]$
  138. [ec2-user@ip-172-31-41-59 my-project]$ docker container ls -a
  139. CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
  140.  
  141. [ec2-user@ip-172-31-41-59 my-project]$ cat Dockerfile
  142. FROM httpd:alpine
  143. COPY ./httpd.conf /usr/local/apache2/conf/httpd.conf
  144. COPY ./public_html/ /usr/local/apache2/htdocs/
  145. CMD ["httpd-foreground"]
  146.  
  147. [ec2-user@ip-172-31-41-59 my-project]$ docker image build -t chris:1 .
  148. Sending build context to Docker daemon  2.286MB
  149. Step 1/4 : FROM httpd:alpine
  150.  ---> d7544b312621
  151. Step 2/4 : COPY ./httpd.conf /usr/local/apache2/conf/httpd.conf
  152.  ---> 0ca4a6a284ac
  153. Step 3/4 : COPY ./public_html/ /usr/local/apache2/htdocs
  154.  ---> cf0f928ee864
  155. Step 4/4 : CMD ["httpd-foreground"]
  156.  ---> Running in d3f5f47e4270
  157. Removing intermediate container d3f5f47e4270
  158.  ---> ed663af15723
  159. Successfully built ed663af15723
  160. Successfully tagged chris:1
  161. [ec2-user@ip-172-31-41-59 my-project]$
  162. [ec2-user@ip-172-31-41-59 my-project]$
  163. [ec2-user@ip-172-31-41-59 my-project]$ docker image ls
  164. REPOSITORY   TAG       IMAGE ID       CREATED          SIZE
  165. chris        1         ed663af15723   11 seconds ago   61.4MB
  166. httpd        alpine    d7544b312621   12 days ago      59.1MB
  167.  
  168. [ec2-user@ip-172-31-41-59 my-project]$ docker container run --name webserver1 -d -p 8081:80 chris:1
  169. a48caf53c935127b04b2aeefaf1cd4d70f7af79b1feb4d19a5fb5fb3a3914a8f
  170. [ec2-user@ip-172-31-41-59 my-project]$
  171. [ec2-user@ip-172-31-41-59 my-project]$
  172.  
  173. ### Version 2 upgrade ####
  174. [ec2-user@ip-172-31-41-59 my-project]$ vim public_html/index.html
  175. [ec2-user@ip-172-31-41-59 my-project]$ docker image build -t chris:2 .
  176. Sending build context to Docker daemon  2.286MB
  177. Step 1/4 : FROM httpd:alpine
  178.  ---> d7544b312621
  179. Step 2/4 : COPY ./httpd.conf /usr/local/apache2/conf/httpd.conf
  180.  ---> Using cache
  181.  ---> e6e162f3127f
  182. Step 3/4 : COPY ./public_html/ /usr/local/apache2/htdocs/
  183.  ---> b313c1c19fea
  184. Step 4/4 : CMD ["httpd-foreground"]
  185.  ---> Running in 972ae2ca49b8
  186. Removing intermediate container 972ae2ca49b8
  187.  ---> 141ae1acc4f6
  188. Successfully built 141ae1acc4f6
  189. Successfully tagged chris:2
  190. [ec2-user@ip-172-31-41-59 my-project]$ docker container run --name webserver2 -d -p 8082:80 chris:2
  191. b4efee80b392133aaadff9d0e4a7c72f8168921edd1ab9879428499f980a21df
  192.  
  193.  
Advertisement
Add Comment
Please, Sign In to add comment