0

I created two apps with NX. An admin frontend as well as a website. Both of these apps have a separate Dockerfile and nginx-default.conf which looks kind of like this:

# Build the whole nx workspace
FROM node:lts-alpine AS builder

WORKDIR /app

COPY ../.. ./

RUN npm i && npm run prodbuild

# Setup nginx to serve the {app}
FROM nginx:alpine

WORKDIR /usr/share/nginx/html

RUN rm -rf ./*

ADD nginx-default.conf /etc/nginx/conf.d/default.conf

COPY --from=builder /app/dist/apps/{app}.

EXPOSE 80

Basically I am building and copying my entire nx workspace everytime just to create the nginx image with the built files. My computer sense is tingling to somehow improve this but I have not yet found any nx information on how to build single apps. Maybe this problem does not have to do with nx but rather Docker? Does someone know how to handle such a situation?

jksevend
  • 418
  • 5
  • 18
  • The general docker multi stage build tips apply, `ADD package.json package-lock.json` then `npm ci` before you add all your files, otherwise your install will never be cached. – Daniel Cooke Nov 08 '22 at 22:02
  • Did you get anywhere with this? When I try to run an Nx build in my Dockerfile, building the image throws an error saying there’s no Nx workspace. – Will Alexander Jun 05 '23 at 17:03

0 Answers0