Hi everyone I m trying …

1 minute read

Hi everyone! I’m trying to deploy a NextJS app in my nx monorepo via Docker. This is part of my CI workflow.

At the moment in the Dockerfile I’m • copying over the entire monorepo • building every dependency in the monorepo • Doing something like ENTRYPOINT nx serve app —prod to take advantage of Next’s built in production server.

Q: can I deploy without having to copy everything in the repo/build every package in the repo? The resulting Docker image has so much unnecessary stuff in it. Thanks


You can always prune non production dependencies with yarn

Hey I’ve never used nextjs but what we do with nestjs is run the build ng build core core is our server project name, then copy over just the builds file in dist/apps/core/ to the docker image. Not sure what next uses to bundle but if it’s webpack it might bundle the dependencies in with it and you won’t need to yarn install inside your docker container! That should speak up your docker build and reduce the size a lot!

Hm that’s a good point . I’ll look into the next build process.

I’ve been a bit confused with next because the docs seem to suggest just a yarn start is what to do in production.

that sounds useful, how does one do that? Is it just a yarn install —production?

maybe the core team might want to chime in on this, but if nx serve is anything like ng serve you don’t want to use that server to run your app in a production environment because it comes with more than what you need for your app to run. the steps I follow when building a docker image from an nx app are: • Create a Dockerfile in the app and add it to the assets of the project in the workspace.json • nx build app-name • Copy the package.json and lockfile to dist/apps/app-namecd dist/apps/app-name && docker build .

And my Dockerfile looks like this (where start:docker is a script in my package.json that does node main.js)

you don’t want dev dependencies in your container because they make your image bigger than it should be

Thanks!! That’s got me going