EADDRINUSE: address already in use :::3000

INFORMATION

Relevant information to this issue:

ISSUE

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?


HOW TO REPRODUCE

Deploy application on port 3000

Hi @moisesrodriguez , this error comes from your app and your container. Could you please share your Dockerfile?

Hi @rophilogene

This is the Dockerfile

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.

1 Like

Can you run this container on your local machine? Does it work without any error? :thinking:

@rophilogene Yes, I have it running locally and it works

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.

@rophilogene No, the problem does not come from that. If you check the logs

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?

@rophilogene I 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 :see_no_evil:

@rophilogene and yes I find it very strange too that another process is listening to 3000 because the app giving the error EADDRINUSE is the ONLY app!

Note that if you use the ENTRYPOINT and CMD 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?

@rophilogene I just deployed this Dockerfile

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

Still have same issue:

@rophilogene any updates on this issue?

Hello @moisesrodriguez ,

I just succeeded to run the same configuration as yours (postgres db + nodejs).
The dockerfile I used is the following one:

WORKDIR /app

COPY . .
COPY [ "package.json", "package-lock.json" ]
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
CMD npx prisma migrate deploy && npm run start

The only differences I get are:

  • RUN npm run build
  • CMD npx prisma migrate deploy && npm run start:prod

Can you share what is done for npm run build and npm run start:prod ? No other process is started by those commands ?

Hi @Melvin_Zottola,

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
  • npx prisma migrate deploy runs Prisma Migrate Overview
  • npm run start:prod is node dist/main

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.

When I looked at your cluster, didn’t see any remaining configuration :thinking:
I will check on my side to remove + re-add the same service