This is a simple self-challenge to test and show docker skills.
This challenge consists of several sections. Each section is a separate branch in this repository. With each achievement, a pull-request is made to the master branch. The master branch contains the incremental final solution.
The first section is to create a simple Node.js application under the folder node-server of this repository. The application should be able to run on port 3000 and should respond to the following routes:
- GET
/status- should respond with a simple string:"NodeJs server is online"
Requirements: Node.js, npm
You can set your .env file or use the default values will solve it either way. To test the solution, run the following commands:
cd node-server
npm install
npm run build
npm run startThe second section is to containerize the previous application. The application should be able to run on port on 3030. This means that:
- A GET request to
localhost:3030/statusshould have the same response of the previous section.
Requirements: Docker.
To test the solution, run the following commands:
docker run -d -p 3030:3000 francogrecco/node-server:production .The third section is to create a second server under the folder node-server-2 of this repository. The application should be able to run on port 4000 and should respond to the following routes:
- GET '/status' - should respond with a simple string:
"Hello from server 2. NodeJs server 2 is online"
Requirements: Node.js, npm
You can set your .env file or use the default values will solve it either way. To test the solution, run the following commands:
cd node-server-2
npm install
npm run build
npm run startThe fourth section is to containerize the previous application. The application should be able to run on port on 4040. This means that:
- A GET request to
localhost:4040/statusshould have the same response of the previous section.
Requirements: Docker
To test the solution, run the following commands:
docker run -d -p 4040:4000 francogrecco/node-server-2:productionThe fifth section is to run both servers. This means that both conditions of the previous section 2 and section 4 should be met:
- A GET request to
localhost:3030/statusshould have the same response of the previous section 2. - A GET request to
localhost:4040/statusshould have the same response of the previous section 4.
Requirements: Docker
To test the solution, run the following commands:
docker run -d -p 3030:3000 francogrecco/node-server:production
docker run -d -p 4040:4000 francogrecco/node-server-2:productionThe sixth section is to run both servers with docker-compose. This means that both conditions of the previous section 5 should be met.
Requirements: Docker, Docker V2 (or docker-compose)
To test the solution, run the following commands:
docker compose up -dThe seventh section is to build a reverse proxy server with Nginx. This means that:
-
A GET request to
localhost/server-1/statusshould have the same response of the previous section 2. -
A GET request to
localhost/server-2/statusshould have the same response of the previous section 4. -
A GET 'localhost:3030/status' should redirect to
localhost/server-1/status. -
A GET 'localhost:4040/status' should redirect to
localhost/server-2/status. -
Any other request should return a 404 error.