Skip to content

Commit 61f9b0a

Browse files
fix: Update root Dockerfile for Railway with proper multi-stage build
1 parent 69d8108 commit 61f9b0a

1 file changed

Lines changed: 30 additions & 13 deletions

File tree

Dockerfile

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,42 @@
1-
# Use Node.js 20 as base image
2-
FROM node:20-slim
1+
# Next.js Production Dockerfile for Railway
2+
# Build context is repository root, website is subdirectory
3+
FROM node:20-alpine AS base
34

5+
# Dependencies stage
6+
FROM base AS deps
7+
RUN apk add --no-cache libc6-compat
48
WORKDIR /app
59

6-
# Copy package files from website directory
710
COPY website/package.json website/package-lock.json* ./
11+
RUN npm ci
812

9-
# Install dependencies
10-
RUN npm ci --legacy-peer-deps
11-
12-
# Copy website files
13+
# Builder stage
14+
FROM base AS builder
15+
WORKDIR /app
16+
COPY --from=deps /app/node_modules ./node_modules
1317
COPY website/ ./
1418

15-
# Build the Next.js application (using Railway-specific build)
19+
ENV NEXT_TELEMETRY_DISABLED=1
1620
RUN npm run build:railway
1721

18-
# Expose port
19-
EXPOSE 8080
22+
# Runner stage
23+
FROM base AS runner
24+
WORKDIR /app
2025

21-
ENV PORT=8080
2226
ENV NODE_ENV=production
27+
ENV NEXT_TELEMETRY_DISABLED=1
28+
29+
RUN addgroup --system --gid 1001 nodejs
30+
RUN adduser --system --uid 1001 nextjs
31+
32+
COPY --from=builder /app/public ./public
33+
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
34+
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
35+
36+
USER nextjs
37+
38+
EXPOSE 3000
39+
ENV PORT=3000
40+
ENV HOSTNAME="0.0.0.0"
2341

24-
# Start the application
25-
CMD ["npm", "run", "start"]
42+
CMD ["node", "server.js"]

0 commit comments

Comments
 (0)