Skip to content

Conversation

@khkim6040
Copy link
Member

@khkim6040 khkim6040 commented Aug 9, 2025

이미지 용량 줄여서 머신 덜 아프게 해주기

  • Dockerignore에 파일 추가
  • next의 standalone 설정
    • 대충 필요한 최소 파일들만 추려주는 기능
  • node_modules 완전 제거 - 409 MB 절약

기존

image

이미지 크기 660 MB

  • COPY node_modules: ~409 MB
  • COPY .next: ~117 MB
  • 베이스 (node:20-alpine ARM64): ~120 MB + 8.5 MB = 128.5 MB
    ─────────────────────────────────────────────
    총 크기: ~660 MB

action 소요 시간: 대략 3분


개선 후

image

이미지 크기 160 MB

  • COPY standalone: 25 MB
  • COPY .next/static: 4.03 MB
  • COPY public: 274 kB
  • 베이스 (node:20-alpine ARM64): ~120 MB + 8.5 MB = 128.5 MB
    ─────────────────────────────────────────────
    총 크기: ~160 MB

action 소요 시간: 2분 40초. 대략 20~30초 정도 절약

로컬에서는 230MB인데 ec2 머신 ARM64에서는 이미지 사이즈가 더 작아짐 굳

정리

구성 요소 이전 방식 현재 방식 절약
node_modules ~409 MB 0 MB 409 MB
.next 폴더 ~117 MB ~29 MB 88 MB
베이스 이미지 ~128.5 MB ~128.5 MB 0 MB
총 크기 ~654.5 MB ~157.8 MB 496.7 MB (76%)

 2 warnings found (use docker --debug to expand):
 - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 14)
 - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 18)
May raise an error
@khkim6040 khkim6040 requested a review from Copilot August 11, 2025 15:59
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR optimizes the Docker build process to reduce image size by leveraging Next.js standalone mode and improving the .dockerignore configuration. The main goal is to reduce machine resource usage by significantly decreasing the Docker image size from ~660MB to ~160MB.

Key Changes

  • Implemented Next.js standalone build configuration to eliminate node_modules dependency in the final image
  • Enhanced .dockerignore with comprehensive exclusions to reduce build context size
  • Modified Dockerfile to use node server.js instead of npm run start for more efficient container startup

Reviewed Changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 5 comments.

File Description
Dockerfile Updated to use Next.js standalone output, removed node_modules copy, and switched to direct Node.js execution
.dockerignore Expanded with comprehensive file exclusions including development tools, logs, and build artifacts

khkim6040 and others added 4 commits August 12, 2025 01:03
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@khkim6040 khkim6040 force-pushed the chore/diet-build-weights branch from de20c59 to b79f8a8 Compare August 13, 2025 03:08
@khkim6040 khkim6040 merged commit 4852397 into main Aug 14, 2025
4 checks passed
@khkim6040 khkim6040 deleted the chore/diet-build-weights branch August 14, 2025 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants