Deploy nodeJS in NX monorepo

I’ve been trying to deploy my NodeJS server but without success. The NX docs in this post Deploying a Node App to | Nx suggest generating the build and uploading it but I got some errors, the Dockerfile seems got issues.
I am stuck on it.

Check your .dockerignore file:

I already did that.

The error is suggesting that dist/apps doesn’t exist on the build machine. That can either be because of one of two things:

  • dist/apps doesn’t exist on your development machine
  • dist/apps isn’t sent to the build machine because it is excluded by the .dockerignore file.

That’s why it is so weird, I can assure you that none of these issues you quote there.

You mentioned a monorepo. Perhaps there is a dist/app directory, but elsewhere in the tree? The Dockerfile is assuming that the dist/app directory is in the current working directory from where you are running fly deploy.

Try reducing your .dockerignore to a bare minimum. Generally uploading too much isn’t a problem other than the time it takes. The following will exclude the two largest directories:


This is my docker file it is on same directory level as my dist directory.

# This file is generated by Nx.
# Build the docker image with `npx nx docker-build server`.
# Tip: Modify "docker-build" options in project.json to change docker build args.
# Run the container with `docker run -p 3000:3000 -t server`.
FROM node:lts-alpine



RUN addgroup --system server && \
          adduser --system -G server server

COPY dist/apps/server server
RUN chown -R server:server .

# You can remove this install step if you build with `--bundle` option.
# The bundled output will include external dependencies.
RUN npm --prefix server --omit=dev -f install

CMD [ "node", "server" ]

If I start with a totally empty directory, just with the following files (including your Dockerfile), fly launch followed by fly deploy succeeds:

% find .

% cat dist/apps/server/index.js
var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.write('Hello World!');

% cat dist/apps/server/package.json
  "scripts": {
    "install": "echo install"

Is your fly.toml on the same level as Dockerfile?

If I run fly launch with the above set of files, yes it will create a fly.toml in the same directory as the Dockerfile.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.