A set of practice tasks for people who new to Docker
Table of Contents
In this project are included a set of tasks designed for beginner Programmers, Systems Administrators, DevOps Engineers, etc. who want to learn or get more familiar with Docker.
This project consists of folders appropriately by the color names of a traffic light: red, yellow, and green. Each of them contains the source code of the appropriate web application.
.
├── _config.yml
├── CODEOWNERS
├── LICENSE
├── README.md
├── red
│ ├── app.js
│ ├── Dockerfile
│ ├── favicon.ico
│ ├── package.json
│ └── index.pug
├── yellow
│ ├── app.js
│ ├── Dockerfile
│ ├── favicon.ico
│ ├── package.json
│ └── index.pug
└── green
├── app.js
├── Dockerfile
├── favicon.ico
├── package.json
└── index.pug
By completing all the instructions of this project, at the end of it, you will have knowledge of:
- the basic commands of the Docker
- networking of the Docker
- container management with Docker compose
- data management by using Docker volumes
- experience with Nginx reverse proxy
Clone this repository, then do the required instructions of the tasks.
1.1 Write a Dockerfile for all applications by following the instructions (from 1.1.1 to 1.1.8) presented below. The created sampler of Dockerfile should be the same for all applications.
- 1.1.1 Docker images must be based on this base image
node:17.0-alpine3.14
- 1.1.2 The working directory inside the containers should be the
/app
directory - 1.1.3 Copy the
package*.json
files to the working directory/app
before installation of thenpm
package manager - 1.1.4 Install the
npm
package manager viaapk
(APK stands for Alpine Linux package keeper/manager). The required version of the npm isnpm=7.17.0-r0
. See how to install packages in Alpine. After the apk instruction install dependency packages with thenmp install
command - 1.1.5 Copy the
app.js
file to the working directory - 1.1.6 Copy the
index.pug
andfavicon.ico
files to the/app/views/
directory - 1.1.7 All containers must expose the port
80
- 1.1.8 All containers should execute the following command:
node app.js
in run time
1.2 Build Docker images for each web app, with following namings:
- trafficlight/red:v1.0
- trafficlight/yellow:v1.0
- trafficlight/green:v1.0
2.1 Create a docker network with name traffic-light
, and assign the 172.20.0.1
as a gateway address with /16
prefix length.
2.2 By using the created images, run containers with following requirements:
-
assign the appropriate names:
red-app
,yellow-app
andgreen-app
to containers -
assign the network
traffic-light
to all containers
2.3 Pull the image nginx:1.21
then run a container with the following requirements:
-
assign the name
nginx-proxy
to the container -
assign the network
traffic-light
to the containernginx-proxy
-
mount the path
~/nginx/conf.d/
of the host to the path/etc/nginx/conf.d/
of the container - for managing configurations from your machine -
the
nginx-proxy
container must listen to the following ports:3000
,4000
and5000
. The mentioned ports should map to the web apps as follows: (3000 -> red-app, 4000 -> yellow-app, 5000 -> green-app). 💡 This point must be implemented via nginx_proxy_pass.
If you have done all points of the Task2 correctly, by opening e.g. the link http://127.0.0.1:3000 on your browser, you should see the red-app
page. The rest web apps should work with the same logic.
3.1 Run services via Docker Compose with the following requirements by using the web apps' images that you've built:
- define the following services:
red-app
,yellow-app
,green-app
andnginx-load-balancer
in docker-compose.yml file - all the services must share the
traffic-light
network
3.2 For the nginx-load-balancer
service mount the paths from the host to the container as follows:
-
~/nginx/conf.d/ -> /etc/nginx/conf.d/
- by allowing configuration management to be done from the host -
/var/log/nginx/ -> /var/log/nginx/
- by making the Nginx logs accessible on the host -
expose the port
80
for thenginx-load-balancer
service
3.3 Make load balancing of request for the all services. 💡 This point must be implemented via Nginx HTTP Load Balancing.
3.4 Restrict access of all web apps with the Nginx HTTP Basic Authentication.
If you have done all points of the Task3 correctly, by visiting with this link: http://127.0.0.1 first time you will see e.g. the red-app
, visiting second time (or refreshing the page) you will see e.g. the yellow-app
, and for the third time you will see the green-app
.
Distributed under the MIT License. See LICENSE
for more information.
Hayk Davtyan | @hayk96