Dockerfile62 lines · 1559 chars # -------------------------------------------
# Dockerfile for Carbon next.js app
# -------------------------------------------
# --------- Builder ---------
FROM node:18-slim as builder
WORKDIR /app
# Install build dependencies
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates \
python3 \
build-essential \
&& rm -rf /var/lib/apt/lists/*
# Install Yarn via Corepack (Node 18 ships Corepack)
RUN corepack enable \
&& corepack prepare yarn@1.22.19 --activate
# Install dependencies first for caching
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile
# Copy all source files and build
COPY . .
RUN yarn build
# --------- Runtime ---------
FROM node:18-slim
WORKDIR /app
ENV NODE_ENV=production
# Install runtime dependencies only
RUN apt-get update \
&& apt-get install -y --no-install-recommends ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Enable Yarn at runtime
RUN corepack enable \
&& corepack prepare yarn@1.22.19 --activate
# Copy built assets from builder
COPY --from=builder /app/.next /app/.next
COPY --from=builder /app/public /app/public
COPY --from=builder /app/next.config.js /app/next.config.js
COPY --from=builder /app/package.json /app/package.json
COPY --from=builder /app/yarn.lock /app/yarn.lock
COPY --from=builder /app/pages /app/pages
COPY --from=builder /app/lib /app/lib
COPY --from=builder /app/components /app/components
# Install production dependencies
RUN yarn install --frozen-lockfile --production
EXPOSE 3000
CMD ["yarn", "start"]