mirror of
https://github.com/docker/awesome-compose.git
synced 2025-04-25 18:28:07 +02:00
Added Nginx, Node and Redis project
This commit is contained in:
parent
6531426a96
commit
22c1733e20
12 changed files with 183 additions and 0 deletions
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');
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue