Created
May 9, 2016 19:49
-
-
Save zerok/64d1ee4dad2c766cd06e4a610aca8f9b to your computer and use it in GitHub Desktop.
Simple NodeJS+Docker setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '2' | |
services: | |
app: | |
build: . | |
volumes: | |
- .:/app | |
entrypoint: nodemon -L main.js | |
ports: | |
- 8080:8080 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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