other Nest container configs depends_on : - redis Add docker-compose fileĪdd a docker-compose.yml file to your project: See the # BUILD FOR LOCAL DEVELOPMENT stage in the Dockerfile above? That's what we'll isolate and target in the docker-compose.yml file. The great thing about multistage builds is that you can target a specific stage in your docker-compose file and run a specific command against the stage. dist # Start the server using the production build CMD node_modules COPY -chown = node:node -from = build /usr/src/app/dist.
#Dockerize nodejs postgres app code
RUN npm ci -only=production & npm cache clean -force USER node # PRODUCTION # FROM node:18-alpine As production # Copy the bundled code from the build stage to the production image COPY -chown = node:node -from = build /usr/src/app/node_modules. # This ensures that the node_modules directory is as optimized as possible. # Passing in -only=production ensures that only the production dependencies are installed. # Run the build command which creates the production bundle RUN npm run build # Set NODE_ENV environment variable ENV NODE_ENV production # Running `npm ci` removes the existing node_modules directory. COPY -chown = node:node -from = development /usr/src/app/node_modules. # So we can copy over the node_modules directory from the development image into this build image. # The Nest CLI is a dev dependency, # In the previous development stage we ran `npm ci` which installed all dependencies. # In order to run `npm run build` we need access to the Nest CLI. # Use the node user from the image (instead of the root user) USER node # BUILD FOR PRODUCTION # FROM node:18-alpine As build WORKDIR /usr/src/app COPY -chown = node:node package*.json.
#Dockerize nodejs postgres app install
# Install app dependencies using the `npm ci` command instead of `npm install` RUN npm ci # Bundle app source COPY -chown = node:node. # Copying this first prevents re-running npm install on every code change. # A wildcard is used to ensure copying both package.json AND package-lock.json (when available). # BUILD FOR LOCAL DEVELOPMENT # FROM node:18-alpine As development # Create app directory WORKDIR /usr/src/app # Copy application dependency manifests to the container image.