“The goal of this example is to show you how to get a Node.js application into a Docker container”
What is Docker? "Docker is an open platform for building, shipping and running distributed applications. It gives programmers, development teams and operations engineers the common toolbox they need to take advantage of the distributed and networked nature of modern applications."
Step 1: Create the Hello World Node.js app •package.json •server.js
package.json { "name": "hellodockerworld", "version": "0.0.0", "private": true, "scripts": { "start": "node server" }, "dependencies": { "express": "~4.14.0" } }
Step 2: Server.js const express = require('express'); // Constants const PORT = 8080; // App const app = express(); app.get('/', function (req, res) { res.send('Hello worldn'); }); app.listen(PORT); console.log('Running on http://localhost:' + PORT);
step 3: .DockerFile “Docker can build images automatically by reading the instructions from a Dockerfile. A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image”
FROM alpine # Update apk and install node RUN apk update && apk upgrade RUN apk add nodejs # Create app directory RUN mkdir -p /app ADD package.json /app WORKDIR /app/ ENV HOME /app ENV NODE_ENV development # Install dependencies RUN npm install # Development Only #VOLUME ["/mnt_vol"] # Production ADD . /app EXPOSE 3000 CMD npm start What is Alpine Linux? Alpine Linux is a Linux distribution built around musl libc and BusyBox. The image is only 5 MB in size and has access to a package repository that is much more complete than other BusyBox based images.
step 4: Build and Run Docker Image Docker build -t hellodocker . docker run -p 8080:3000 hellodocker Now check this in browser http://127.0.0.1:8080 Go to the directory that has your Dockerfile and run the following command to build the Docker image.
Thank you for watching ! Adil adilm717@gmail.com

Docker + Node "hello world" Application

  • 2.
    “The goal ofthis example is to show you how to get a Node.js application into a Docker container”
  • 3.
    What is Docker? "Dockeris an open platform for building, shipping and running distributed applications. It gives programmers, development teams and operations engineers the common toolbox they need to take advantage of the distributed and networked nature of modern applications."
  • 4.
    Step 1: Createthe Hello World Node.js app •package.json •server.js
  • 5.
    package.json { "name": "hellodockerworld", "version": "0.0.0", "private":true, "scripts": { "start": "node server" }, "dependencies": { "express": "~4.14.0" } }
  • 6.
    Step 2: Server.js constexpress = require('express'); // Constants const PORT = 8080; // App const app = express(); app.get('/', function (req, res) { res.send('Hello worldn'); }); app.listen(PORT); console.log('Running on http://localhost:' + PORT);
  • 7.
    step 3: .DockerFile “Dockercan build images automatically by reading the instructions from a Dockerfile. A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image”
  • 8.
    FROM alpine # Updateapk and install node RUN apk update && apk upgrade RUN apk add nodejs # Create app directory RUN mkdir -p /app ADD package.json /app WORKDIR /app/ ENV HOME /app ENV NODE_ENV development # Install dependencies RUN npm install # Development Only #VOLUME ["/mnt_vol"] # Production ADD . /app EXPOSE 3000 CMD npm start What is Alpine Linux? Alpine Linux is a Linux distribution built around musl libc and BusyBox. The image is only 5 MB in size and has access to a package repository that is much more complete than other BusyBox based images.
  • 9.
    step 4: Buildand Run Docker Image Docker build -t hellodocker . docker run -p 8080:3000 hellodocker Now check this in browser http://127.0.0.1:8080 Go to the directory that has your Dockerfile and run the following command to build the Docker image.
  • 11.
    Thank you forwatching ! Adil adilm717@gmail.com