Dockerfile:
###############################################
Dockerfile to build a sample web application
docker build -t mynodejs .
###############################################
Base image is node
FROM node:6-alpine
WORKDIR /myapp
RUN npm update
RUN npm install redis@3 # redis version 3
#RUN npm install -g redis@3 # redis version 3
ADD example.js /myapp/example.js
docker-compose.yml:
---
services:
web:
build: .
command: node /myapp/example.js
links:
- redis
ports:
- 8080:80
redis:
image: redis:latest
example.js:
// A Simple Request/Response web application
var http = require('http');
var url = require('url');
var redis = require('redis');
var client = redis.createClient(6379, 'redis');
// client.connect();
client.set("/", "Welcome to docker-compose helper \nEnter the argument in the URL\n", redis.print);
client.set("/up", "Start up a service", redis.print);
client.set("/stop", "Stop a service", redis.print);
client.set("/kill", "Kill a service", redis.print);
var server = http.createServer(function (request, response) {
var href = url.parse(request.url, true).href;
response.writeHead(200, {"Content-Type": "text/plain"});
// Pull the response (value) string using the URL
client.get(href, function (err, reply) {
if ( reply == null ) response.write("Command: " + href.slice(1) + " unknown\n");
else response.write(reply + "\n");
response.end();
});
});
console.log("Listening on port 80");
server.listen(80);