From 7e8a6f7fb2e454b6e582bc15aa5d02509788cdd8 Mon Sep 17 00:00:00 2001 From: Sanchit Bhatnagar Date: Sun, 13 Sep 2020 13:12:17 +0530 Subject: [PATCH] Implementing Docker-Compose --- visits/Dockerfile | 9 +++++++++ visits/docker-compose.yml | 10 ++++++++++ visits/index.js | 22 ++++++++++++++++++++++ visits/package.json | 9 +++++++++ 4 files changed, 50 insertions(+) create mode 100644 visits/Dockerfile create mode 100644 visits/docker-compose.yml create mode 100644 visits/index.js create mode 100644 visits/package.json diff --git a/visits/Dockerfile b/visits/Dockerfile new file mode 100644 index 0000000..ae72bf3 --- /dev/null +++ b/visits/Dockerfile @@ -0,0 +1,9 @@ +FROM node:alpine + +WORKDIR '/app' + +COPY package.json . +RUN npm install +COPY . . + +CMD ["npm" , "start"] \ No newline at end of file diff --git a/visits/docker-compose.yml b/visits/docker-compose.yml new file mode 100644 index 0000000..d6382bf --- /dev/null +++ b/visits/docker-compose.yml @@ -0,0 +1,10 @@ +version: '3' + +services: + redis-server: + image: 'redis' + node-app: + restart: on-failure + build: . + ports: + - "4001:8081" diff --git a/visits/index.js b/visits/index.js new file mode 100644 index 0000000..b1b8d55 --- /dev/null +++ b/visits/index.js @@ -0,0 +1,22 @@ +const express = require('express') +const redis = require('redis') + +const app = express() + +const client = redis.createClient({ + host: 'redis-server', + port: 6379 +}) + +client.set('visits', 0) + +app.get('/', (req, res) => { + client.get('visits', (err, visits) => { + res.send('Number of Visits is ' + visits) + client.set('visits', parseInt(visits) + 1) + }) +}) + +app.listen(8081, (params) => { + console.log('Lisitng on Port 8081') +}) \ No newline at end of file diff --git a/visits/package.json b/visits/package.json new file mode 100644 index 0000000..342d8cb --- /dev/null +++ b/visits/package.json @@ -0,0 +1,9 @@ +{ + "dependencies": { + "express":"*", + "redis":"2.8.0" + }, + "scripts": { + "start": "node index.js" + } +} \ No newline at end of file