The App
For this guide, we'll use a simple Node.js app as an example, but the same principles can be applied to any app:
const express = require('express');
// Constants
const PORT = 8080;
const HOST = '0.0.0.0';
// App
const app = express();
app.get('/simple-web-app', (req, res) => {
res.send('Hello world\n');
});
app.listen(PORT, HOST);
console.log(`Running on http://${HOST}:${PORT}`);
That's it! It's a classic express "Hello World" starter app that listens for requests on port 8080
. For this example
walkthrough, save this file as server.js
.
Since we need to pull in the dependencies to run this app, we will also need a corresponding package.json
:
{
"name": "docker_web_app",
"version": "1.0.0",
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"dependencies": {
"express": "^4.16.1"
}
}