fly deploy not working for NodeJs application

I have been trying to get my typescript express application deployment to work but the logs show no red flags.

I have already

  • checked logs and the the console log is there (server started at port 8080!!)
  • tried all trouble shooting steps
  • tried ssh and the file system looks good (tried netstat and it does show that a node process is running on port 8080)
  • tried fly vm status and application state is passing

Here’s my Dockerfile for reference

FROM node:17-alpine as build-image
WORKDIR /usr/src/app
COPY package*.json ./
COPY tsconfig.json ./
COPY ./src ./src
RUN npm ci
RUN npx tsc

FROM node:17-alpine
WORKDIR /usr/src/app
COPY package*.json ./
COPY --from=build-image /usr/src/app/dist ./dist
RUN npm ci --production
COPY . .
CMD [ "node", "dist/index.js" ]

Accessing the application from web gives 404 error whereas it works locally

If you have any suggestions do let me know,
Thank you.

If it is okay, can you share this app’s fly.toml?

I hope the build step (npx tsc) is transpiling up expected output in ./dist. One way to check would be if the docker image responds to requests just fine locally on your PC.

Also, I’m curious about another npm ci in your runner… Wouldn’t that be redundant? In fact, should you run npm ci --production in the builder stage, instead?

1 Like

Thanks for responding,

So for build stage devDependencies will be needed for compilation to work (eg: let’s say I replace npx tsc with a build script that uses rimraf )

For the production stage, devDepenedencies will not be needed hence installing them separately instead of copying the node_modules from build stage.

1 Like

in my case the issue was with .dockerignore, it had many unnecessary files which might have caused the issue, after cleaning up .dockerignore the issue was fixed.

Current .dockerignore

1 Like


I guess I thought wrong that npx tsc would have bundled up all required dependencies into the output dir, dist/.