Nextjs Dockerfile Application Failed To Respond

trevor-trinh
HOBBYOP

a month 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

8 Replies

Railway
BOT

a month 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
HOBBYTop 10% Contributor

a month ago

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


trevor-trinh
HOBBYOP

a month ago

Hello, thank you for the quick response.

Fixing


a month ago

3000 != 8080


That will need to match as 8080.


trevor-trinh
HOBBYOP

a month ago

My bad just noticed oops


Status changed to Solved brody 28 days ago


trevor-trinh
HOBBYOP

a month ago

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


Status changed to Awaiting Railway Response Railway 28 days ago


Status changed to Solved trevor-trinh 28 days ago


fra
HOBBYTop 10% Contributor

a month ago


Status changed to Awaiting Railway Response Railway 28 days ago


Status changed to Solved brody 28 days ago


Loading...
Nextjs Dockerfile Application Failed To Respond - Railway Help Station