C.W.K.
Stream
Lesson 02 of 06 · published

Build Context & .dockerignore — .git 보내지 마

~10 min · dockerfile, performance

Level 0Container 호기심
0 XP0/36 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

docker build . 끝의 점이 build context

docker build . 돌리면 현재 디렉토리 전체가 Docker 데몬으로 보내져. 모든 파일. 모든 byte. .git, node_modules, .venv — 다.

50KB Python 프로젝트가 node_modules 가 거기 있으면 1GB build context 돼. Build 가 느리게 느껴지는 게 — layer 빌드 전에 전체 context 가 unix socket 으로 dockerd 한테 가야 하니까.

해결은 .dockerignore

.gitignore 랑 같은 아이디어. 매치되는 거 build context 에서 제외.

Code

탄탄한 .dockerignore baseline·text
# Version control
.git
.gitignore

# Python caches
__pycache__
*.pyc
*.pyo
.pytest_cache
.mypy_cache
.venv
venv

# Node
node_modules
npm-debug.log*

# IDE / OS noise
.vscode
.idea
.DS_Store

# Local secrets — never bake into images
.env
.env.local
*.pem
*.key

# Docker itself
Dockerfile
docker-compose*.yml
.dockerignore

# Build artifacts you don't need at runtime
dist
build
*.log
차이 보기·bash
# Without .dockerignore, watch the build context size:
docker build -t myapp:1.0 .
# Sending build context to Docker daemon: 1.42GB

# Add .dockerignore, rebuild:
docker build -t myapp:1.0 .
# Sending build context to Docker daemon: 47.3kB

External links

Exercise

본인 프로젝트에서 docker build . 돌리고 'Sending build context to Docker daemon' 줄 적어. 꼼꼼한 .dockerignore 추가, rebuild, 새 크기 적어. 얼마 절약했어? .dockerignore commit.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.