I’m getting EADDRINUSE error, when there is only a database deployed and this one application that is being deployed. I don’t have anything else running. How is this possible?
FROM node:20.9.0-alpine AS base
WORKDIR /app
COPY . .
COPY [ "package.json", "package-lock.json", "./" ]
RUN npm ci
RUN npm install prisma --save-dev
FROM base AS migrate
ENV NODE_ENV=migration
COPY --from=base /app ./
CMD npm run migration:run
FROM base AS dev
ENV NODE_ENV=development
ENV RUN_SEEDER=false
COPY --from=base /app ./
CMD npm run migration:run && npm run start:dev
FROM dev AS debug
ENV NODE_ENV=debug
CMD [ "npm", "run", "start:debug"]
FROM base AS prod
EXPOSE 80
ENV NODE_ENV=production
COPY --from=base /app ./
RUN npm install -g @nestjs/cli
RUN npm run build
ENTRYPOINT npx prisma migrate deploy && npm run start:prod
As you can see from the logs, it only creates the base and prod layers since there is no way to select a target in Qovery yet (hopefully this gets implemented).
As a note, I was able to deploy this app with the current settings. I don’t remember why I deleted it, but now no matter how many times I redeploy or delete and create it again, I will get this error. Now that I think about it, don’t know if something is lingering from when I first deployed successfully and then deleted it.
Do you think the problem could come from the multiple CMD commands? I have to check how it behaves on Kubernetes - that’s the only thing that runs multiple times your server.
it only runs the base layer which has no CMD, and then it runs the prod layer. This is the expected behavior since no target was selected. Prod layer is the one that runs ENTRYPOINT npx prisma migrate deploy && npm run start:prod.
Yes I agreed that’s the expected behavior. I just wonder if I’m not missing anything but my team will take a look. If you get this error message from your app it just means that another process is really listening on port 3000 inside your container. Which is obviously strange.
Hum, I’m noticing this:
ENTRYPOINT npx prisma migrate deploy && npm run start:prod
Why do you use an ENTRYPOINT here instead of a CMD?
@rophilogeneI read this article a long time and it stuck with me the use of ENTRYPOINT. But as you can see from the stages I still use CMD because of habit
Note that if you use the ENTRYPOINTandCMD command it can leads to this kind of issue. Can you confirm that you only use the CMD command? Can you show the final Dockerfile you are using?
FROM node:20.9.0-alpine AS base
WORKDIR /app
COPY . .
COPY [ "package.json", "package-lock.json", "./" ]
RUN npm ci
RUN npm install prisma --save-dev
FROM base AS prod
EXPOSE 80
ENV NODE_ENV=production
COPY --from=base /app ./
RUN npm install -g @nestjs/cli
RUN npm run build
CMD npx prisma migrate deploy && npm run start:prod
With that dockerfile, I was able to deploy it on the first try. But I deleted the app and added it again, and after that, I kept getting that error. I assume if I change my port it will work, maybe it was not deleted correctly? My intuition is that we should explore the issue in that direction.
npm run build is is a wrapper on top of the standard tsc compiler
It finally deployed. The only thing that I changed was that I was exposing port 80 in the Dockerfile instead of 3000. So in a sense the error EADDRINUSE doesn’t make sense. But for the time being, we have an app deployed.