In this lab you will:
In this lab, we will deploy several different setups. This time there will not be a default docker-compose.yml
in your lab folder, but rather one for each application architecture we deploy.
This introduces the -f
option to the docker-compose
command to allow the user to provide a configuration in place of the standard docker-compose.yml
file.
This lab prep’s a little different as we will be scaling the workstation image to use 5 containers.
ist346-labs
PS > cd ist346-labs
PS ist346-labs> git pull origin master
lab-F
folder:PS ist346-labs> cd lab-F
PS ist346-labs\lab-F> dir *.yml
2-tier.yml
, 3-tier.yml
and n-tier.yml
for each of the three services we will setup in this lab.In this first part we will host a static website for our made-up company, Fudgemart.com. We will deploy the nginx https://www.nginx.com/ server running the HTTP protocol to serve up the HTML of the homepage for the site. This is a classic example of a 2-tier client-server application architecture with web browser on your host being the client and the Docker container running the Nginx web server being the server of course.
Inside the container we will expose TCP port 80, the well-known port for the HTTP protocol to the host. This allows the web browser running on the host to have access to the Nginx web server running inside the Docker container.
You will use the chrome
web browser on your host computer to access the web server.
+-----SERVER:WEB----+
| Docker: nginx |--+
|http://webserver:80| |
+-------------------+ | +--CLIENT:BROWSER---+ ++++++++++++++
+--|host computer |---| Internet |
|http://localhost:80| ++++++++++++++
+-------------------+
PS ist346-labs\lab-F> docker-compose -f 2-tier.yml up -d
-f 2-tier.yml
to the command to specify that specific docker-compose file.PS ist346-labs\lab-F> docker-compose -f 2-tier.yml ps
nginx
is running. Furthermore the container has TCP ports 22 and 80 in use, but only port 80 is exposed to the host 0.0.0.0:80 -> 80/tcp
http://localhost:80
Every service has a mechanism to log requests to access resources which the service provides. This is very important as it gives administrators a complete history of attempted to access a resource. The client has no control over the logging process, the service running on the server does it as part of its operations.
Let’s view the log output in real time so we can see logging in action.
PS ist346-labs\lab-F> start powershell
+-------------------------+
| browser | powershell |
| | 2 |
+------------+ |
| powershell | |
| 1 | |
+------------+------------+
powershell 1
window, let’s connect to the console of the web server:PS ist346-labs\lab-F> docker-compose -f 2-tier.yml exec nginx bash
root@webserver:/#
access.log
file. This file, as configured by the Nginx service, records all requests made to the web server by any clients. To watch the file for changes, type:root@webserver:/# tail -F /var/log/nginx/access.log
browser
enter the following address http://localhost/hackme
404
can you find it? It’s right after "GET /hackme HTTP/1.1"
Yes, that’s right, what ever you type in the browser’s address bar is recorded by the server!You might be wondering about the information you see in the log. The log is entries are in the Common Log format. Specifically:
172.44.6.1
in the log you see.- -
represent the user identifier and logged in user requesting the document, since we are accessing without logging in, these are - -
.[11/Sep/2018:4:50:00]
"GET /hackme HTTP/1.1"
, means the client made a GET
request to the resource /hackme
using the HTTP/1.1
protocol. There are different Request Methods you can make as part of the HTTP/1.1 protocol.404
but common response codes are 200
(ok) and 304
(Not modified)304
the number of bytes should be 0
.Windows NT 10.0
Indicating the request was made from a computer running Windows 10, and it says Chrome
indicating the chrome browser was used to make the request.All this information is recorded at each request and it’s quite useful for figuring out exactly what users are doing on your website. This is the business of Web Analytics!
Keep the log watcher going as we continue with this part of the lab.
In the two-tier model, our nginx web server is just serving HTML pages to our client, as such if we want to edit the contents of this site, we must know HTML. To make things easier to change, our docker setup has exposed the folder serving the webpages to the host as 2-tier\html
. This way we do not have to connect to the console of the container to edit files and instead we can use the host. When we edit the contents of this folder, then reload the page we we should see the updated site.
Let’s put that to the test.
powershell 2
window, let’s move into the html
folder, type:PS ist346-labs\lab-F> cd 2-tier\html
PS ist346-labs\lab-F\2-tier\html>
Let’s open the index.html
file in notepad, type:PS ist346-labs\lab-F\2-tier\html> notepad index.html
notepad
utility should open. You will see HTML markup for the webpage. We’re going to edit this page and add a Sporting Goods department. This is a bit of a challenge because you need to know HTML to do this. Find the line that says:<li>Housewares</li>
<li>Sporting Goods</li>
so that the markup now looks like this: <li>Housewares</li>
<li>Sporting Goods</li>
</ul>
notepad
utility, and make sure to save the file when you exit.browser
and enter the website http://localhost:80
you should now see an updated page with Sporting Goods added as a department.
powershell 1
window. You should see "GET /"
with a 200
status code indicating the response was OK.304
because the content was not modified.powershell 1
log window.lab-F
folder by moving up two folders, type:PS ist346-labs\lab-F\2-tier\html> cd ..\..
PS ist346-labs\lab-F> docker-compose -f 2-tier.yml down
In this next part we will host the Fudgemart.com website using the MKDocs static site generator. A static site generator creates HTML content from the markdown format. MKDocs will handle the process of detecting changes in the content and automatically sending a reload request to any clients. Nginx, running on tcp port 80 is configured to forward requests to the MKDocs service on tcp port 8000. This is a common use case for nginx: to act as an HTTP reverse-proxy for an another HTTP service (in this case, its MKDocs). Typically the reverse proxy configured on a public IP address and handles forwarding HTTP traffic to multiple web applications on a private network.
What makes this example 3-Teir is we have:
+----SERVER:WEB-----+
| Docker: nginx |---+
+------|http://webserver:80| |
| +-------------------+ | +---CLIENT:BROWSER----+ ++++++++++++++
+----SERVER:LOGIC----+ +--| host computer |---| Internet |
| Docker: MKDocs | | http://localhost:80 | ++++++++++++++
| http://mkdocs:8000 | +---------------------+
+--------------------+
Let’s explore how this 3 tier setup works and at the same time demonstrate the advantages of markdown over the HTML format when it comes to managing content.
PS ist346-labs\lab-F> docker-compose -f 3-tier.yml up -d
PS ist346-labs\lab-F> docker-compose -f 3-tier.yml ps
nginx
exposing tcp port 80
and mkdocs
exposing tcp port 8000
http://localhost:80
This docker setup has the logs configured to redirect to stdout. This allows us to use docker-compose
to inspect the logs. This is a common method of logging while you are testing your container setup.
nginx
logs, type:PS ist346-labs\lab-F> docker-compose -f 3-tier.yml logs nginx
nginx
is the name of the container service."GET /"
is actually made up of several other supporting files and scripts.PS ist346-labs\lab-F> docker-compose -f 3-tier.yml logs mkdocs
In this section, we will explore the advantages of a business logic tier like MKDocs to update a website as opposed to simply editing HTML content directly. Once again we have exposed the contents of the website which are inside the container to a local folder, this time 3-tier\docs
.
PS ist346-labs\lab-F> notepad 3-tier\docs\mkdocs.yml
name: mkdocs
name: material
browser
you will see the page has reloaded automatically and there is a new site theme!PS ist346-labs\lab-F> notepad 3-tier\docs\docs\index.md
- Housewares
:- Sporting Goods
PS ist346-labs\lab-F> docker-compose -f 3-tier.yml down
In this final part we will deploy an N-tier content/blog application, wordpress. WordPress allows users to create websites without any knowledge of HTML. It’s the classic example of the benefits of an N-Tier application - ease of use for the end user as the HTML is being created by the WordPress application itself based on user actions from its friendly user interface. Here’s a summary of the tiers in this setup.
Mysql, the database layer where the application stores content and changes, running on port tcp 3306. The WordPress application talks to the database over this port.
PS ist346-labs\lab-F> docker-compose -f n-tier.yml up -d
PS ist346-labs\lab-F> docker-compose -f n-tier.yml ps
nginx
exposing tcp port 80
and wordpress
exposing tcp port 8080
and mysql
exposing tcp 3306
.http://localhost
. Install Wordpress
At this point you are encouraged to play around! If you screw things up you can always tear down the environment and bring it back up again. Some things to try:
PS ist346-labs\lab-F> docker-compose -f n-tier.yml down
-f
option do to the docker-compose
command?snickers bars
into your favorite search engine, is that information being logged? Based on what you learned in this lab, do you know this?docker-compose
command to view the mysql
logs from the n-tier
example.