Containerizing an Express server.
This repository is a step by step guide for setting up and containerizing an express server. This repository also serves as a complementary guide for this article.
- Create a folder
- Open a terminal and initial NPM on the folder.
npm init -y
- Install express-generator
npm install express-generator -g
- Bootstrap application skeleton
- Install express server dependencies
- Add a docker file from iron/node
FROM iron/node WORKDIR /app # Copy package.json + package-lock.json files COPY package*.json ./ # Installing dependencies RUN npm install # Bundle app source COPY . . EXPOSE 3000 ENTRYPOINT [ "npm", "start" ]
- Add the .dockerignore file below
- Create a docker image by executing the command below on your app folder.
docker build --tag express/iron-api .
- Verify that your docker image was built.
docker images --all
- Instantiate a container out of the image you created.
docker run -p 3000:3000 --name iron-api express/iron-api
- Open the following link on a browser. http://localhost:3000/