How to Docker-ise a NestJs App

Visakh Vijayan
2 min readJul 5, 2024

If you are a fan of JS then you will like NestJs. NestJs is a framework of NodeJs which has a strong focus on architecture. It modularises the whole application into a service-oriented architecture that makes imagining services easy.

Today we will look at how we can Docker-ise such an application so that we can get up and running easily. Docker allows us to easily deploy things on the server.

We have a boilerplate of NestJs which has some of the basic functionalities out of the box. Remember, this is an ongoing development process where we are trying to make a product that will allow one to dive into making a product immediately.

You will be able to find a file named Dockerfile in the repository. That is where the magic is happening. Below is the code as in the file —

FROM node:20

WORKDIR /app

COPY package*.json /app/

RUN npm install

COPY . /app/

RUN npx prisma generate

RUN npm run build

EXPOSE 3000

CMD ["npm", "run", "start"]

A couple of points

  1. We are using node:20 as a base image. This contains both the runtime and the Linux operating system inside it so it runs easily.
  2. Since we are using Prisma for connecting to databases we have that extra command inside it. So we have to run the prisma generate command to get the…

--

--

Visakh Vijayan

Techie from Kerala, India. Days are for coding, nights for weaving tales of tech, travel, and finance. Join me in exploring this multifaceted journey