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
- Create a folder
- Open a terminal application on your machine (CMD, BASH, ASH, etc..) an initialize NPM on the folder
- Install express-generator, it enables you to quickly create an express application skeleton.
- Bootstrap the express application skeleton
- Install express server dependencies
- 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.
- 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)
- Create a docker image by executing the command below on your app folder.
- Verify that your docker image was built.
- Instantiate a container from the image you created.
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
- Microservices: Picking the .NET Framework for your containerized applications.
- Microservices: Why choose containers over virtual machines.