Added Nginx, Node and Redis project
Signed-off-by: ajeetraina <ajeetraina@gmail.com>
This commit is contained in:
parent
468b963db0
commit
657dc7c97f
25
nginx-nodejs-redis/docker-compose.yml
Normal file
25
nginx-nodejs-redis/docker-compose.yml
Normal file
@ -0,0 +1,25 @@
|
||||
version: '3.9'
|
||||
services:
|
||||
redis:
|
||||
image: 'redis:alpine'
|
||||
ports:
|
||||
- '6379:6379'
|
||||
web1:
|
||||
restart: on-failure
|
||||
build: ./web1
|
||||
ports:
|
||||
- '81:5000'
|
||||
web2:
|
||||
restart: on-failure
|
||||
build: ./web2
|
||||
ports:
|
||||
- '82:5000'
|
||||
nginx:
|
||||
build: ./nginx
|
||||
ports:
|
||||
- '80:80'
|
||||
depends_on:
|
||||
- web1
|
||||
- web2
|
||||
|
||||
|
3
nginx-nodejs-redis/nginx/Dockerfile
Normal file
3
nginx-nodejs-redis/nginx/Dockerfile
Normal file
@ -0,0 +1,3 @@
|
||||
FROM nginx
|
||||
RUN rm /etc/nginx/conf.d/default.conf
|
||||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
12
nginx-nodejs-redis/nginx/nginx.conf
Normal file
12
nginx-nodejs-redis/nginx/nginx.conf
Normal file
@ -0,0 +1,12 @@
|
||||
upstream loadbalancer {
|
||||
server web1:5000;
|
||||
server web2:5000;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
location / {
|
||||
proxy_pass http://loadbalancer;
|
||||
}
|
||||
}
|
9
nginx-nodejs-redis/web/Dockerfile
Normal file
9
nginx-nodejs-redis/web/Dockerfile
Normal file
@ -0,0 +1,9 @@
|
||||
FROM node:alpine
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
COPY ./package.json ./
|
||||
RUN npm install
|
||||
COPY ./server.js ./
|
||||
|
||||
CMD ["npm","start"]
|
15
nginx-nodejs-redis/web/package.json
Normal file
15
nginx-nodejs-redis/web/package.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "web",
|
||||
"version": "1.0.0",
|
||||
"description": "Running Node.js and Express.js on Docker",
|
||||
"main": "server.js",
|
||||
"scripts": {
|
||||
"start": "node server.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"express": "^4.17.2",
|
||||
"redis": "3.1.2"
|
||||
},
|
||||
"author": "",
|
||||
"license": "MIT"
|
||||
}
|
23
nginx-nodejs-redis/web/server.js
Normal file
23
nginx-nodejs-redis/web/server.js
Normal file
@ -0,0 +1,23 @@
|
||||
const express = require('express');
|
||||
const redis = require('redis');
|
||||
const app = express();
|
||||
const redisClient = redis.createClient({
|
||||
host: 'redis',
|
||||
port: 6379
|
||||
});
|
||||
|
||||
app.get('/', function(req, res) {
|
||||
redisClient.get('numVisits', function(err, numVisits) {
|
||||
numVisitsToDisplay = parseInt(numVisits) + 1;
|
||||
if (isNaN(numVisitsToDisplay)) {
|
||||
numVisitsToDisplay = 1;
|
||||
}
|
||||
res.send('Number of visits is: ' + numVisitsToDisplay);
|
||||
numVisits++;
|
||||
redisClient.set('numVisits', numVisits);
|
||||
});
|
||||
});
|
||||
|
||||
app.listen(5000, function() {
|
||||
console.log('Web application is listening on port 5000');
|
||||
});
|
9
nginx-nodejs-redis/web1/Dockerfile
Normal file
9
nginx-nodejs-redis/web1/Dockerfile
Normal file
@ -0,0 +1,9 @@
|
||||
FROM node:alpine
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
COPY ./package*.json ./
|
||||
RUN npm install
|
||||
COPY ./server.js ./
|
||||
|
||||
CMD ["npm","start"]
|
15
nginx-nodejs-redis/web1/package.json
Normal file
15
nginx-nodejs-redis/web1/package.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "web1",
|
||||
"version": "1.0.0",
|
||||
"description": "Running Node.js and Express.js on Docker",
|
||||
"main": "server.js",
|
||||
"scripts": {
|
||||
"start": "node server.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"express": "^4.17.2",
|
||||
"redis": "3.1.2"
|
||||
},
|
||||
"author": "",
|
||||
"license": "MIT"
|
||||
}
|
24
nginx-nodejs-redis/web1/server.js
Normal file
24
nginx-nodejs-redis/web1/server.js
Normal file
@ -0,0 +1,24 @@
|
||||
const express = require('express');
|
||||
const redis = require('redis');
|
||||
const app = express();
|
||||
const redisClient = redis.createClient({
|
||||
host: 'redis',
|
||||
port: 6379
|
||||
});
|
||||
|
||||
|
||||
app.get('/', function(req, res) {
|
||||
redisClient.get('numVisits', function(err, numVisits) {
|
||||
numVisitsToDisplay = parseInt(numVisits) + 1;
|
||||
if (isNaN(numVisitsToDisplay)) {
|
||||
numVisitsToDisplay = 1;
|
||||
}
|
||||
res.send('web1: Total number of visits is: ' + numVisitsToDisplay);
|
||||
numVisits++;
|
||||
redisClient.set('numVisits', numVisits);
|
||||
});
|
||||
});
|
||||
|
||||
app.listen(5000, function() {
|
||||
console.log('Web app is listening on port 5000');
|
||||
});
|
9
nginx-nodejs-redis/web2/Dockerfile
Normal file
9
nginx-nodejs-redis/web2/Dockerfile
Normal file
@ -0,0 +1,9 @@
|
||||
FROM node:alpine
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
COPY ./package.json ./
|
||||
RUN npm install
|
||||
COPY ./server.js ./
|
||||
|
||||
CMD ["npm","start"]
|
15
nginx-nodejs-redis/web2/package.json
Normal file
15
nginx-nodejs-redis/web2/package.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "web2",
|
||||
"version": "1.0.0",
|
||||
"description": "Running Node.js and Express.js on Docker",
|
||||
"main": "server.js",
|
||||
"scripts": {
|
||||
"start": "node server.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"express": "^4.17.2",
|
||||
"redis": "3.1.2"
|
||||
},
|
||||
"author": "",
|
||||
"license": "MIT"
|
||||
}
|
24
nginx-nodejs-redis/web2/server.js
Normal file
24
nginx-nodejs-redis/web2/server.js
Normal file
@ -0,0 +1,24 @@
|
||||
const express = require('express');
|
||||
const redis = require('redis');
|
||||
const app = express();
|
||||
const redisClient = redis.createClient({
|
||||
host: 'redis',
|
||||
port: 6379
|
||||
});
|
||||
|
||||
|
||||
app.get('/', function(req, res) {
|
||||
redisClient.get('numVisits', function(err, numVisits) {
|
||||
numVisitsToDisplay = parseInt(numVisits) + 1;
|
||||
if (isNaN(numVisitsToDisplay)) {
|
||||
numVisitsToDisplay = 1;
|
||||
}
|
||||
res.send('web2: Total number of visits is: ' + numVisitsToDisplay);
|
||||
numVisits++;
|
||||
redisClient.set('numVisits', numVisits);
|
||||
});
|
||||
});
|
||||
|
||||
app.listen(5000, function() {
|
||||
console.log('Web app is listening on port 5000');
|
||||
});
|
Loading…
Reference in New Issue
Block a user