Skip to content

Instantly share code, notes, and snippets.

@gionn
Last active August 29, 2015 14:18
Show Gist options
  • Save gionn/3b8ae2fd16f46acadea9 to your computer and use it in GitHub Desktop.
Save gionn/3b8ae2fd16f46acadea9 to your computer and use it in GitHub Desktop.
Simple example of Dockerfile for nodejs application
var http = require('http');
// handle all request with a 200 ok
var server = http.createServer(function (request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
text = "Running Node.js:" + process.versions.node
response.end(text);
});
// search for an injected port or use a default one
var port = process.env.PORT;
// go!
server.listen(port);
// logs con terminal that server is ready
console.log("Server running at http://0.0.0.0:" + port + "/");
FROM ubuntu:14.04
MAINTAINER Giovanni Toraldo
ENV DEBIAN_FRONTEND noninteractive
RUN sed -i s/archive/it.archive/g /etc/apt/sources.list
RUN apt-get update
RUN apt-get install -y software-properties-common
RUN apt-add-repository ppa:chris-lea/node.js
RUN apt-get update
RUN apt-get install -y nodejs
RUN apt-get clean
RUN rm -rf /var/lib/apt/lists/*
RUN mkdir /var/www
ADD app.js /var/www/app.js
ENV PORT 8080
EXPOSE 8080
VOLUME ["/var/www/data"]
CMD ["/usr/bin/node", "/var/www/app.js"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment