#Railway having trouble connecting to local db upon deployment

12 messages · Page 1 of 1 (latest)

dusty steppe
#

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.

silk rivetBOT
#

Project ID: 63ba6dbb-f4be-49b5-9c9f-bd5e83221ed9

dusty steppe
fresh axle
#

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

dusty steppe
#

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.

fresh axle
#

interesting, are you deploying an alpine based image?

dusty steppe
#

yes

#
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
fresh axle
#

in that case add a ENABLE_ALPINE_PRIVATE_NETWORKING service variable set to true

dusty steppe
#

aha nice, now it successfully connects, thanks.

fresh axle
#

Awesome, no problem