Railway having trouble connecting to local db upon deployment

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`.
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.
No description
Solution:
in that case add a ENABLE_ALPINE_PRIVATE_NETWORKING service variable set to true
Jump to solution
10 Replies
Percy
Percy8mo ago
Project ID: 63ba6dbb-f4be-49b5-9c9f-bd5e83221ed9
misimilen
misimilenOP8mo ago
63ba6dbb-f4be-49b5-9c9f-bd5e83221ed9
Fragly
Fragly8mo ago
Could you try adding a 3 second sleep in your start command?
misimilen
misimilenOP8mo 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.
Fragly
Fragly8mo ago
interesting, are you deploying an alpine based image?
misimilen
misimilenOP8mo ago
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
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
Solution
Fragly
Fragly8mo ago
in that case add a ENABLE_ALPINE_PRIVATE_NETWORKING service variable set to true
misimilen
misimilenOP8mo ago
aha nice, now it successfully connects, thanks.
Fragly
Fragly8mo ago
Awesome, no problem
Want results from more Discord servers?
Add your server