How to dockerize nestjs app in nx monorepo

28 Views Asked by At

I am working on Nx monorepo with several projects inside. Now, I need to dockerize my nestjs app.

I am not sure how to create Docker file inside the 'backend' folder ( my nestjs app ), to be executed as expected.

Normally I am starting the app using this command: yarn run nx backend:serve But this doesn't work on the docker. It says that command nx backend:serve is not found.

My dockerfile looks like this:

FROM node:20.9.0-alpine3.18

WORKDIR /src

RUN npm add --global nx@latest

# Copy package.json and package-lock.json from the root of the build context
COPY package*.json ./

# Install dependencies
RUN yarn  

# Expose the port the app runs on
EXPOSE 3000

# Command to run the application
CMD [ "yarn", "run","nx backend:serve" ]
0

There are 0 best solutions below