Skip to main content

Basics


Create App

yarn create next-app --typescript

Directory Structure

<package>
├── next.config.js
├── next-env.d.ts
├── node_modules/
├── package.json
├── pages/ # 디렉토리 구조를 통한 API 라우팅
│ ├── api/
│ │ └── hello.ts # <domain>/api/hello
│ ├── _app.tsx # 모든 페이지에 공통으로 적용될 Warpper
│ └── index.tsx # <domain>/
├── public/ # static files
│ ├── favicon.ico # <domain>/favicon.ico
│ └── vercel.svg
├── README.md
├── styles/
│ ├── globals.css
│ └── Home.module.css
├── tsconfig.json
└── yarn.lock

Dockerfile

next.config.js
module.exports = {
experimental: {
outputStandalone: true,
},
};
FROM node:16-alpine AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile

FROM node:16-alpine AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

ENV NEXT_TELEMETRY_DISABLED 1

RUN yarn build

FROM node:16-alpine AS runner
WORKDIR /app

ENV NODE_ENV production
ENV NEXT_TELEMETRY_DISABLED 1

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

# You only need to copy next.config.js if you are NOT using the default configuration
# COPY --from=builder /app/next.config.js ./
COPY --from=builder /app/public ./public
COPY --from=builder /app/package.json ./package.json

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

USER nextjs

EXPOSE 3000

ENV PORT 3000

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