

Create a new file notes-api/api/Dockerfile with the following content: FROM node:ltsĪ Dockerfile is a collection of instructions that the Docker daemon uses to build a new image. Start the server by executing the npm run start command.Copy the package.json file into the image.Set a working directory other than the root.Get a good base image for running JavaScript applications, like node.In my opinion, the containerization process of this application should have the following steps:
Docker ip resolution between stacks code#
For now, just ignore them.īefore you start to write the necessary code for containerizing this application, plan out the individual steps. The boot.sh, build.sh, destroy.sh, shutdown.sh, and Makefile will come into action later in this article. The api subdirectory contains the application source code. It uses Knex.js as the query builder and Objection.js as the object-relational mapper. The application is powered by Express.js and uses PostgreSQL as its database system. There is no hassle of authentication whatsoever. This is a very simple notes application that lets you create, read, update, and delete notes from the database. Let me give you an overview of the notes-api project. I prefer Visual Studio Code with the official Docker Extension. Make sure you’re on the master branch and open the notes-api directory from this repository in your favorite code editor. Just make a fork and clone that on your local system. The code can be found on the fhsinchy/docker-handbook-projects GitHub repository. You’ll work with a simple notes application API powered by Express.js and PostgreSQL. If you’re looking for a resource that’ll teach you Docker from the ground up, The Docker Handbook is highly recommended. The focus of this article will be on containerizing Node.js applications and will assume that you already have Docker installed on your system and basic knowledge of working with the tool. Most of the work throughout this article will be done in a terminal and all the containers will be Linux containers so having familiarity with one of the distros will help. This article assumes that you have experience working with Node.js and have developed APIs using Express.js in the past. You’ll also learn about working with networks, volumes, and docker-compose.

In this article, you’ll not only learn about putting your application inside an image but also optimize that image to have a very small size and high stability. Yet, so many Node.js developers struggle to containerize their Node.js application with Docker efficiently. Both of these technologies have brought about changes so big that they can be considered evolutions. Node.js and Docker are probably the most uttered words these days in the web development scene and rightfully so.
