10 Steps to Setup and Containerize an Express Server

This article is a step by step guide on how to bootstrap and containerize an Express Server using Iron Node as a base image in 10 Easy steps. The end result of this guide is an 83 MB Image that can be used to instantiate an alpine container with express server running on port 3000.

Download POC from GITHUB

Pre-requisites

Steps

  1. Create a folder
  2. Open a terminal application on your machine (CMD, BASH, ASH, etc..) an initialize NPM on the folder
  3. Install express-generator, it enables you to quickly create an express application skeleton.
  4. Bootstrap the express application skeleton
  5. Install express server dependencies
  6. Add the Dockerfile below (Name it "Dockerfile" without extension) to the root directory of your project's source code. It is basically a file that instructs the Docker engine on how to create a Docker image for your application. It uses a base image provided by iron/node which is an optimized variant of alpine node which is more smaller than the original alpine image.
  7. Add the .dockerignore file below, this will prevent node_modules folder and node logs from getting baked in your image. This will prevent issues from baking images on windows machines (express has varying dependencies on different os installations)
  8. Create a docker image by executing the command below on your app folder.
  9. Verify that your docker image was built.
  10. Instantiate a container from the image you created.

Results

An 83 MB docker image based on iron/node that can be instantiated or pushed through docker registries like Azure Container Registry or Amazon Container Registry.

You have a running container that contains an express server which listens on port 3000.

You can navigate to http://localhost:3000 and view your express server


Related Articles


Full blood geek?

Comments

  1. Replies
    1. Hi,

      Thanks for pointing out the unclear part, I really appreciate feedback. I updated the section and to point out the specific update. You have to a add an extension-less file named "Dockerfile" to the root directory of your source code directory. This is basically a file that instructs the Docker Engine on how to build a container image.

      Thanks and I hope the update helps.
      Allan

      Delete

Post a Comment

Popular posts from this blog

Replicating Netflix Part 1: Installing Raspbian Lite using Etcher

HTTP 2 Server Push

Microservices: Why choose Containers over Virtual Machines.