Nextjs Dockerfile Application Failed To Respond
trevor-trinh
HOBBYOP

10 months ago

I have a nextjs project and have a local dockerfile. I want the port to stay 3000 (instead of railway 8080) for local development and my docker compose. This is my current frontend docker.

# Stage 1: Builder
FROM oven/bun:1 AS builder

WORKDIR /app

# Copy package files
COPY package.json bun.lockb* ./

# Install dependencies
RUN bun install --frozen-lockfile

# Copy source
COPY . .

ARG NEXT_PUBLIC_API_URL
ARG NEXT_PUBLIC_WS_URL

# Set environment variables for Next.js build
ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL
ENV NEXT_PUBLIC_WS_URL=$NEXT_PUBLIC_WS_URL

ENV NEXT_TELEMETRY_DISABLED=1
RUN bun run build

# Stage 2: Runtime
FROM oven/bun:1-slim

WORKDIR /app

# Copy built application from builder
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
COPY --from=builder /app/public ./public

ENV HOSTNAME=0.0.0.0
ENV PORT=3000

EXPOSE 3000

CMD ["bun", "server.js"]

I didn't have the ENV hostname and port and this is what I'd see in the build logs.

From seeing some comments on here I guess I'm supposed to set the port manually and now see:

However when I visit the public website I get "Application Failed to respond" and "connection refused" in the logs.

It's a simple website, just nextjs template + shadcn install. Running it directly on vercel works.

Appreciate the help!

Solved$10 Bounty

Pinned Solution

fra
HOBBY

10 months ago

Can you change the port in settings -> public network (click edit on your public domain) to match you Port?

8 Replies

Railway
BOT

10 months ago

Hey there! We've found the following might help you get unblocked faster:

If you find the answer from one of these, please let us know by solving the thread!


fra
HOBBY

10 months ago

Can you change the port in settings -> public network (click edit on your public domain) to match you Port?


trevor-trinh
HOBBYOP

10 months ago

Hello, thank you for the quick response.

Fixing


10 months ago

3000 != 8080


10 months ago

That will need to match as 8080.


trevor-trinh
HOBBYOP

10 months ago

My bad just noticed oops


Status changed to Solved brody 10 months ago


trevor-trinh
HOBBYOP

10 months ago

Trolled so hard, my bad team. Thanks for the quick help


Status changed to Awaiting Railway Response Railway 10 months ago


Status changed to Solved trevor-trinh 10 months ago


fra
HOBBY

10 months ago

🙂


Status changed to Awaiting Railway Response Railway 10 months ago


Status changed to Solved brody 10 months ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...