Railway having trouble connecting to local db upon deployment
afinvoice
HOBBYOP

2 years ago

Hi. I recently deployed my node.js app on Railway and found out that during startup of my node.js app, railway was unable to connect/find the local db instance. It eventually was able to connect to it, after a few retries. Is the problem on my side?

Error: P1001: Can't reach database server at `postgres.railway.internal`:`5432`
Please make sure your database server is running at `postgres.railway.internal`:`5432`.

Not once does the local db instance restart during deployment of the app.

10 Replies

afinvoice
HOBBYOP

2 years ago

63ba6dbb-f4be-49b5-9c9f-bd5e83221ed9


dev
MODERATOR

2 years ago

Could you try adding a 3 second sleep in your start command?


afinvoice
HOBBYOP

2 years ago

Now I only get the connection error once and on the second startup it successfully connects and I bet I get no error if I sleep like 6 seconds or so because first time I had two of these.


dev
MODERATOR

2 years ago

interesting, are you deploying an alpine based image?


afinvoice
HOBBYOP

2 years ago

yes


afinvoice
HOBBYOP

2 years ago

FROM node:21-alpine AS base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable

FROM base AS builder
RUN apk add --no-cache libc6-compat
RUN apk update
WORKDIR /app
RUN pnpm add turbo --global
COPY . .
RUN turbo prune backend --docker

FROM base AS installer
RUN apk add --no-cache libc6-compat
RUN apk update
WORKDIR /app

COPY .gitignore .gitignore
COPY --from=builder /app/out/json/ .
COPY --from=builder /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
COPY --from=builder /app/out/full/packages/backend/prisma ./packages/backend/prisma 
RUN pnpm install
COPY --from=builder /app/out/full/ .
RUN pnpm turbo build --filter backend

FROM base AS runner
WORKDIR /app
COPY --from=installer /app .
CMD pnpm start:backend

dev
MODERATOR

2 years ago

in that case add a ENABLE_ALPINE_PRIVATE_NETWORKING service variable set to true


dev
MODERATOR

2 years ago

if you're curious about why this is necassery:


afinvoice
HOBBYOP

2 years ago

aha nice, now it successfully connects, thanks.


dev
MODERATOR

2 years ago

Awesome, no problem


Loading...