docker build -t <your username>/node-web-app .
docker images
docker run -p <customPort>:<nodePort> -d <your username>/node-web-app
#Print the output of your app:
# Get container ID
$ docker ps
# Print app output
$ docker logs <container id>
# Example
Running on http://localhost:8080
# Enter the container
$ docker exec -it <container id> /bin/bash
node_modules
npm-debug.log
FROM node:7
# Create app directory
WORKDIR /app
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json /app
RUN npm install
# If you are building your code for production
# RUN npm install --only=production
# Bundle app source
COPY . /app
CMD [ "npm", "start" ]
EXPOSE 8080
{
"name": "docker_web_app",
"version": "1.0.0",
"description": "Node.js on Docker",
"author": "First Last <first.last@example.com>",
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"dependencies": {
"express": "^4.16.1"
}
}
//create app file
//example
'use strict';
const express = require('express');
// Constants
const PORT = 8080;
const HOST = '0.0.0.0';
// App
const app = express();
app.get('/', (req, res) => {
res.send('Hello world\n');
});
app.listen(PORT, HOST);
console.log(`Running on http://${HOST}:${PORT}`);