Create a working directory:
mkdir simpleweb
cd simpleweb
Create a package.json file:
$ cat package.json
{
"dependencies": {
"express": "*"
},
"scripts": {
"start": "node index.js"
}
}
Create a NodeJS app:
$ cat index.js
const express = require('express');
const app = express();
app.get('/', (req, res) => {
res.send('Hello, world!');
});
app.listen(8080, () => {
console.log('Listening on port 8080');
});
Create a Dockerfile:
$ cat Dockerfile
FROM node:alpine
WORKDIR /usr/app
COPY ./package.json .
RUN npm install
COPY ./index.js .
CMD ["npm", "start"]
Build and tag the image:
docker build -t simpleweb .
Run the dockerized app:
docker run -p 8080:8080 simpleweb
Open the browser and navigate to http://127.0.0.1:8080