Skip to content

Instantly share code, notes, and snippets.

@zerok
Created May 9, 2016 19:49
Show Gist options
  • Save zerok/64d1ee4dad2c766cd06e4a610aca8f9b to your computer and use it in GitHub Desktop.
Save zerok/64d1ee4dad2c766cd06e4a610aca8f9b to your computer and use it in GitHub Desktop.
Simple NodeJS+Docker setup
version: '2'
services:
app:
build: .
volumes:
- .:/app
entrypoint: nodemon -L main.js
ports:
- 8080:8080
FROM node:4
# Prepare non-root user and folders
RUN useradd --system --user-group --create-home app && \
mkdir /app && chown app:app /app
RUN npm install -g nodemon
# Install dependency outside of the app volume
COPY package.json /opt/
RUN cd /opt && npm install
ENV NODE_PATH=/opt/node_modules
VOLUME ["/app"]
USER app
WORKDIR /app
EXPOSE 8080
ENTRYPOINT ["/app/entrypoint.sh"]
const Hapi = require('hapi');
const server = new Hapi.Server();
server.connection({
host: '0.0.0.0',
port: 8080
});
server.route({
path: '/',
method: 'GET',
handler: (req, reply) => {
reply('Hello!');
}
});
server.start(err => {
if (err) {
console.log(err);
process.exit(1);
}
console.log('Listening on 0.0.0.0:8080');
});
{
"name": "nodejs-in-docker",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"hapi": "^13.4.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment