Git Product home page Git Product logo

trafficlight-docker-challenge's Introduction

Contributors Forks Stargazers Issues MIT License LinkedIn Medium Stackoverflow

๐Ÿšฆ Traffic Light Docker Challenge

A set of practice tasks for people who new to Docker

Table of Contents
  1. About The Project
  2. Project Structure
  3. Requirements
  4. What you will learn
  5. Getting Started
  6. License
  7. Author and maintainer

About The Project

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.

Project structure

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

Requirements

What you will learn

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

Getting started

Clone this repository, then do the required instructions of the tasks.

1๏ธโƒฃ Task1: Writing Dockerfiles and building Docker images

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 the npm package manager
  • 1.1.4 Install the npm package manager via apk (APK stands for Alpine Linux package keeper/manager). The required version of the npm is npm=7.17.0-r0. See how to install packages in Alpine. After the apk instruction install dependency packages with the nmp install command
  • 1.1.5 Copy the app.js file to the working directory
  • 1.1.6 Copy the index.pug and favicon.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๏ธโƒฃ Task2: Running web apps behind Nginx reverse proxy

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 and green-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 container nginx-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 and 5000. 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๏ธโƒฃ Task3: Running web apps with Nginx load balancing

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 and nginx-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 the nginx-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.

License

Distributed under the MIT License. See LICENSE for more information.

Author and maintainer

Hayk Davtyan | @hayk96

trafficlight-docker-challenge's People

Contributors

hayk96 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

trafficlight-docker-challenge's Issues

Answer pls

Im stuck on configuring the nginx conf

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.