Dockerizing a Simple Web Application

  1. Create NodeJS Web Application
const http = require('http');
const hostname = '0.0.0.0';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
nodejs app.js
{
"name": "nodejsapp",
"version": "1.0.0",
"description": "Simple Hello World Application",
"main": "app.js",
"scripts": {
"start": "node app.js"
},
"author": "Medium Member",
"license": "ISC"
}
  1. which image should be used, what applications or libraries ought to be installed beforehand,
  2. which configurations should be added, and finally
  3. what command should be executed to run the application.
FROM node:alpine
WORKDIR /app
COPY package*.json .
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "start"]
docker build . -t nodejsapp
docker run -p 3000:3000 nodejsapp
browser: http://localhost:3000
or curl http://localhost:3000

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Pre-configured React Native Project using react-native-app-builder NPM

react-native-app-builder

CSRF in ICEHRM 31.0.0.0S in Delete User Endpoint

Learning JavaScript from Scrimba.com

Should I use Context API or Redux?

React Native Fiber — a starter kit focused on animations

What’s new in Create-React-App v4 & React 17

React: LifeCycle Methods Replicated with Hooks

Reflection: Unit Testing With Complex Objects

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
cem akpolat

cem akpolat

More from Medium

Getting started with Git & GitHub . . .

One Doc-A functional and visual web application

SQL Tutorial. Installing MySQL Workbench and MySQL Server on Windows

Test your API using Rest Client VS Code Extension (No Postman, Insomnia needed)