Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #---------------------------------------------------- Creating New Directory --------------------------------------------#
- [ec2-user@ip-172-31-41-59 my-project]$ mkdir public_html
- [ec2-user@ip-172-31-41-59 my-project]$ touch public_html/{home.html,index.html,about.html}
- [ec2-user@ip-172-31-41-59 my-project]$ ls public_html/
- about.html home.html index.html
- [ec2-user@ip-172-31-41-59 my-project]$ echo "<h1><center>This is home.html page</h1></center>" > public_html/home.html
- [ec2-user@ip-172-31-41-59 my-project]$ echo "<h1><center>This is index.html page</h1></center>" > public_html/index.html
- [ec2-user@ip-172-31-41-59 my-project]$ echo "<h1><center>This is about.html page</h1></center>" > public_html/about.html
- #---------------------------------------------------- Alpine image --------------------------------------------#
- [ec2-user@ip-172-31-41-59 my-project]$ docker image pull httpd:alpine
- alpine: Pulling from library/httpd
- 8a49fdb3b6a5: Pull complete
- beb66a906b34: Pull complete
- 01924573e8db: Pull complete
- 255f194b76b3: Pull complete
- 0f48f8ea2bc9: Pull complete
- 390cbd08c8ae: Pull complete
- Digest: sha256:3e25d419bf180122f5f9af5cf2180709d8234320ff25514a61f5d1bc3cf46394
- Status: Downloaded newer image for httpd:alpine
- docker.io/library/httpd:alpine
- [ec2-user@ip-172-31-41-59 my-project]$ docker image ls
- REPOSITORY TAG IMAGE ID CREATED SIZE
- httpd alpine d7544b312621 12 days ago 59.1MB
- [ec2-user@ip-172-31-41-59 my-project]$ docker container run \
- > --name webserver \
- > -d \
- > -p 80:80 \
- > -v $(pwd)/public_html/:/usr/local/apache2/htdocs \
- > httpd:alpine
- d77eacee9328bf29dea44998d530a545c2dd4b35d57a06c941fcbc87abedff68
- [ec2-user@ip-172-31-41-59 my-project]$ curl http://ec2-15-206-73-205.ap-south-1.compute.amazonaws.com
- <h1><center>This is index.html page</h1></center>
- [ec2-user@ip-172-31-41-59 my-project]$ docker container exec webserver ls -l /usr/local/apache2/htdocs
- total 12
- -rw-r--r-- 1 1000 1000 50 May 24 07:39 about.html
- -rw-r--r-- 1 1000 1000 49 May 24 07:38 home.html
- -rw-r--r-- 1 1000 1000 50 May 24 07:38 index.html
- [ec2-user@ip-172-31-41-59 my-project]$
- [ec2-user@ip-172-31-41-59 my-project]$
- [ec2-user@ip-172-31-41-59 my-project]$
- [ec2-user@ip-172-31-41-59 my-project]$ docker container logs webserver
- 103.158.218.18 - - [24/May/2023:07:50:29 +0000] "GET / HTTP/1.1" 304 -
- 103.158.218.18 - - [24/May/2023:07:50:29 +0000] "GET / HTTP/1.1" 304 -
- [ec2-user@ip-172-31-41-59 my-project]$
- [ec2-user@ip-172-31-41-59 my-project]$
- [ec2-user@ip-172-31-41-59 my-project]$ docker container logs -f webserver
- 103.158.218.18 - - [24/May/2023:07:56:10 +0000] "-" 408 -
- 103.158.218.18 - - [24/May/2023:07:59:08 +0000] "GET / HTTP/1.1" 304 -
- 103.158.218.18 - - [24/May/2023:08:00:00 +0000] "-" 408 -
- #---------------------------------------------------- DocIndex change --------------------------------------------#
- [ec2-user@ip-172-31-41-59 my-project]$ docker container exec -it webserver sh
- /usr/local/apache2 #
- /usr/local/apache2 #
- /usr/local/apache2 # apk add vim
- /usr/local/apache2 # grep DirectoryIndex conf/httpd.conf
- /usr/local/apache2 #
- # DirectoryIndex: sets the file that Apache will serve if a directory
- DirectoryIndex home.html index.html about.html
- [ec2-user@ip-172-31-41-59 my-project]$ curl http://ec2-15-206-73-205.ap-south-1.compute.amazonaws.com
- <h1><center>This is index.html page</h1></center>
- [ec2-user@ip-172-31-41-59 my-project]$
- [ec2-user@ip-172-31-41-59 my-project]$ docker container restart webserver
- webserver
- [ec2-user@ip-172-31-41-59 my-project]$
- [ec2-user@ip-172-31-41-59 my-project]$ curl http://ec2-15-206-73-205.ap-south-1.compute.amazonaws.com
- <h1><center>This is home.html page</h1></center>
- #---------------------------------------------------- Copying file to local system --------------------------------------------#
- [ec2-user@ip-172-31-41-59 my-project]$ docker container cp webserver:/usr/local/apache2/conf/httpd.conf .
- [ec2-user@ip-172-31-41-59 my-project]$
- [ec2-user@ip-172-31-41-59 my-project]$
- [ec2-user@ip-172-31-41-59 my-project]$ ll
- total 24
- -rw-r--r--. 1 ec2-user ec2-user 20848 May 24 08:06 httpd.conf
- drwxr-xr-x. 2 ec2-user ec2-user 59 May 24 07:34 public_html
- [ec2-user@ip-172-31-41-59 my-project]$
- [ec2-user@ip-172-31-41-59 my-project]$
- [ec2-user@ip-172-31-41-59 my-project]$ docker container stop webserver
- webserver
- [ec2-user@ip-172-31-41-59 my-project]$ docker container rm webserver
- webserver
- [ec2-user@ip-172-31-41-59 my-project]$ docker container ls -a
- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- #---------------------------------------------------- Creating a new container --------------------------------------------#
- [ec2-user@ip-172-31-41-59 my-project]$ docker container run \
- > --name webserver \
- > -d \
- > -p 80:80 \
- > -v $(pwd)/httpd.conf:/usr/local/apache2/conf/httpd.conf \
- > -v $(pwd)/public_html/:/usr/local/apache2/htdocs/ \
- > httpd:alpine
- 27188f1cc86f3c1fd59abdd0b6b78631cc7374bc89ca009ab8bf349c1d78c0c2
- [ec2-user@ip-172-31-41-59 my-project]$
- [ec2-user@ip-172-31-41-59 my-project]$ grep DirectoryIndex httpd.conf
- # DirectoryIndex: sets the file that Apache will serve if a directory
- DirectoryIndex about.html index.html home.html
- [ec2-user@ip-172-31-41-59 my-project]$
- [ec2-user@ip-172-31-41-59 my-project]$ docker container restart webserver
- webserver
- [ec2-user@ip-172-31-41-59 my-project]$
- [ec2-user@ip-172-31-41-59 my-project]$ curl http://ec2-15-206-73-205.ap-south-1.compute.amazonaws.com
- <h1><center>This is about.html page</h1></center>
- [ec2-user@ip-172-31-41-59 my-project]$
- [ec2-user@ip-172-31-41-59 my-project]$ echo "<h1><center>This is about.html updated page</h1></center>" > public_html/about.html
- [ec2-user@ip-172-31-41-59 my-project]$
- [ec2-user@ip-172-31-41-59 my-project]$ curl http://ec2-15-206-73-205.ap-south-1.compute.amazonaws.com
- <h1><center>This is about.html updated page</h1></center>
- [ec2-user@ip-172-31-41-59 my-project]$
- #---------------------------------------------------- Docker Image Creation --------------------------------------------#
- [ec2-user@ip-172-31-41-59 my-project]$ docker container stop webserver
- webserver
- [ec2-user@ip-172-31-41-59 my-project]$
- [ec2-user@ip-172-31-41-59 my-project]$ docker container rm webserver
- webserver
- [ec2-user@ip-172-31-41-59 my-project]$
- [ec2-user@ip-172-31-41-59 my-project]$ docker container ls -a
- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- [ec2-user@ip-172-31-41-59 my-project]$ cat Dockerfile
- FROM httpd:alpine
- COPY ./httpd.conf /usr/local/apache2/conf/httpd.conf
- COPY ./public_html/ /usr/local/apache2/htdocs/
- CMD ["httpd-foreground"]
- [ec2-user@ip-172-31-41-59 my-project]$ docker image build -t chris:1 .
- Sending build context to Docker daemon 2.286MB
- Step 1/4 : FROM httpd:alpine
- ---> d7544b312621
- Step 2/4 : COPY ./httpd.conf /usr/local/apache2/conf/httpd.conf
- ---> 0ca4a6a284ac
- Step 3/4 : COPY ./public_html/ /usr/local/apache2/htdocs
- ---> cf0f928ee864
- Step 4/4 : CMD ["httpd-foreground"]
- ---> Running in d3f5f47e4270
- Removing intermediate container d3f5f47e4270
- ---> ed663af15723
- Successfully built ed663af15723
- Successfully tagged chris:1
- [ec2-user@ip-172-31-41-59 my-project]$
- [ec2-user@ip-172-31-41-59 my-project]$
- [ec2-user@ip-172-31-41-59 my-project]$ docker image ls
- REPOSITORY TAG IMAGE ID CREATED SIZE
- chris 1 ed663af15723 11 seconds ago 61.4MB
- httpd alpine d7544b312621 12 days ago 59.1MB
- [ec2-user@ip-172-31-41-59 my-project]$ docker container run --name webserver1 -d -p 8081:80 chris:1
- a48caf53c935127b04b2aeefaf1cd4d70f7af79b1feb4d19a5fb5fb3a3914a8f
- [ec2-user@ip-172-31-41-59 my-project]$
- [ec2-user@ip-172-31-41-59 my-project]$
- ### Version 2 upgrade ####
- [ec2-user@ip-172-31-41-59 my-project]$ vim public_html/index.html
- [ec2-user@ip-172-31-41-59 my-project]$ docker image build -t chris:2 .
- Sending build context to Docker daemon 2.286MB
- Step 1/4 : FROM httpd:alpine
- ---> d7544b312621
- Step 2/4 : COPY ./httpd.conf /usr/local/apache2/conf/httpd.conf
- ---> Using cache
- ---> e6e162f3127f
- Step 3/4 : COPY ./public_html/ /usr/local/apache2/htdocs/
- ---> b313c1c19fea
- Step 4/4 : CMD ["httpd-foreground"]
- ---> Running in 972ae2ca49b8
- Removing intermediate container 972ae2ca49b8
- ---> 141ae1acc4f6
- Successfully built 141ae1acc4f6
- Successfully tagged chris:2
- [ec2-user@ip-172-31-41-59 my-project]$ docker container run --name webserver2 -d -p 8082:80 chris:2
- b4efee80b392133aaadff9d0e4a7c72f8168921edd1ab9879428499f980a21df
Advertisement
Add Comment
Please, Sign In to add comment