Skip to content

Commit

Permalink
Implementing Docker-Compose
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanchit Bhatnagar committed Sep 13, 2020
1 parent 51e7647 commit 7e8a6f7
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
9 changes: 9 additions & 0 deletions visits/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM node:alpine

WORKDIR '/app'

COPY package.json .
RUN npm install
COPY . .

CMD ["npm" , "start"]
10 changes: 10 additions & 0 deletions visits/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: '3'

services:
redis-server:
image: 'redis'
node-app:
restart: on-failure
build: .
ports:
- "4001:8081"
22 changes: 22 additions & 0 deletions visits/index.js
Original file line number Diff line number Diff line change
@@ -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')
})
9 changes: 9 additions & 0 deletions visits/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"dependencies": {
"express":"*",
"redis":"2.8.0"
},
"scripts": {
"start": "node index.js"
}
}

0 comments on commit 7e8a6f7

Please sign in to comment.