docker
파일을 셋팅하고 최적화 작업을 한 내용을 기록용
FROM node:20.5.1-alpine3.17 AS base
FROM base AS deps
FROM base AS images
FROM base AS builder
FROM base AS runner
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
FROM base AS images
WORKDIR /app
COPY ./public/res ./public/res
FROM node:20-alpine AS base
glibc
대신 musl libc
를 사용하는 것으로 보인다. (리눅스 시스템에서 표준 C 라이브러리 - GNU Library C)glibc
, musl libc
키워드에 대해 주의해야 겠다 (경량화 버전 사용으로 문제 발생 시 에러 메세지에 언급될 수 있으므로;;)This variant is useful when final image size being as small as possible is your primary concern.
pnpm i
을 할 때 --frozen-lockfile
옵션은 처음 알게 되었다COPY package.json pnpm-lock.yaml* ./
// package.json
// ...
"packageManager": "pnpm@8.0.0",
"pnpm": {
"peerDependencyRules": {
"allowedVersions": {
"react": "^18",
"react-dom": "^18"
}
},
// ...
# ci.yaml
- name: Next.js cache
uses: actions/cache@v3
with:
path: ${{ github.workspace }}/.next/cache
key: ${{ runner.os }}-${{ runner.node }}-${{ hashFiles('**/pnpm-lock.yaml') }}-nextjs
# ci.yaml
- name: export Next.js cache
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
target: cache
outputs: type=local,dest=.
# Dockerfile
COPY .next/cache ./.next/cache
# syntax=docker/dockerfile:1.4
ENV NEXT_TELEMETRY_DISABLED 1
const nextConfig = getConfig({
// ...
output: 'standalone',
// ...
});
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
https://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile
https://jaynote2022.tistory.com/entry/README-19
https://patrick-f.tistory.com/59
https://kyoung-jnn.com/posts/nextjs-build-optimization-in-ci