Skip to content

Commit

Permalink
fix: dockerfile copy하는 항목 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
JjungminLee committed Jan 29, 2024
1 parent 61a6032 commit b719349
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,44 +1,58 @@
# multi-stage build as deps
FROM node:18-alpine AS deps
FROM node:18-alpine AS deps

RUN apk add --no-cache libc6-compat

#dpes의 app 디렉토리에 package.json 복붙
WORKDIR /app
COPY package.json postcss.config.js tailwind.config.ts tsconfig.json .env
COPY package.json postcss.config.js tailwind.config.ts .env ./
# yarn
RUN yarn --prefer-offline --frozen-lockfile
RUN yarn add sharp
# 이미지 최적화
RUN yarn add sharp

# multi-stage build as builder
FROM node:18-alpine AS builder
FROM node:18-alpine AS builder

# deps의 node_modules를 builder/app/node_modules로 복붙
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

# 현재 디렉토리 확인
RUN ls -a

# 빌드
RUN yarn build
RUN yarn prebuild && yarn build

# final stage
FROM node:18-alpine AS runner

WORKDIR /app
ENV NODE_ENV=production

# 사용자 그룹 nodejs 추가
# nodejs에 유저 nextjs 추가
RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001

# builder에서 빌드했던 결과물 중 public, package.json 복붙
COPY --from=builder /app/public ./public
COPY --from=builder /app/package.json /app/postcss.config.js /app/tailwind.config.ts /app/tsconfig.json /app/.env
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/postcss.config.ts ./postcss.config.ts
COPY --from=builder /app/tailwind.config.ts ./tailwind.config.ts
COPY --from=builder /app/.env ./.env

# 복사 경로 수정
# builder에서 빌드했던 결과물 중 static, standalone 복붙 소유자와 소유그룹도 변경
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

# nextjs
USER nextjs

# 열어둘 포트 설정
EXPOSE 3000

# 이미지 안 환경변수 설정
ENV PORT 3000

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

0 comments on commit b719349

Please sign in to comment.