educacion@educacion:~/src/docker02$ cat Dockerfile
FROM node
WORKDIR /code
RUN npm install -g nodemon
COPY package.json /code/package.json
RUN npm install && npm ls
RUN mv /code/node_modules /node_modules
COPY . /code
CMD ["npm", "start"]
educacion@educacion:~/src/docker02$ cat docker-compose.yml
version: "2"
services:
web:
build: .
command: nodemon -L --inspect=0.0.0.0:5858
volumes:
- .:/code
ports:
- "8000:8000"
- "5858:5858"
educacion@educacion:~/src/docker02$ cat package.json
{
"main": "app.js",
"dependencies": {
"express": "~4.14.0",
"express-handlebars": "~3.0.0"
}
}
educacion@educacion:~/src/docker02$ cat app.js
const express = require('express');
const expressHandlebars = require('express-handlebars');
const http = require('http');
const PORT = 8000;
const LINES = [
"One thing at the time.",
"Start from the beginning!",
"Up to date!",
"As Simple As Possible",
];
let lineIndex = 0;
const app = express();
app.engine('html', expressHandlebars());
app.set('view engine', 'html');
app.set('views', __dirname);
app.get('/', (req, res) => {
let message = LINES[lineIndex];
lineIndex += 1;
if (lineIndex >= LINES.length) {
lineIndex = 0;
}
res.render('index', {message: message});
});
http.Server(app).listen(PORT, () => {
console.log("HTTP server listening on port %s", PORT);
});
educacion@educacion:~/src/docker02$ cat index.html
< !doctype html>
< html>
< head>
< meta http-equiv="refresh" content="2">
< style type="text/css">
.sample_docker_nodejs {
font-family: Helvetica, Arial, sans-serif;
font-weight: 600;
font-size: 56pt;
text-transform: uppercase;
text-align: center;
background: #3c3;
color: white;
}
< /style>
< /head>
< body class='sample_docker_nodejs'>“{{message}}”Think the best of others
No comments:
Post a Comment