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

Dockerfile 기본 — FROM, WORKDIR, COPY, RUN, CMD

~16 min · dockerfile, basics

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

명령 6개로 대부분의 Dockerfile 커버

  • FROM — base image. 모든 Dockerfile 이 여기서 시작.
  • WORKDIR — 작업 디렉토리 설정 (없으면 만듦). cd 대신 이거 써.
  • COPY — build context 의 파일을 image 에 복사.
  • RUN — build 시점에 명령 실행 (새 layer 만듦).
  • EXPOSE — 앱이 어떤 포트 듣는지 문서화. 순수 메타데이터.
  • CMD — container 시작 시 디폴트 명령.

실제 동작하는 Dockerfile

아래는 동작하는 FastAPI Dockerfile. 의도적으로 단순 — multi-stage 아직 X, non-root 아직 X — 6개 핵심 명령을 자연스러운 순서로. Track 2 에서 각각 확장.

Code

최소 FastAPI Dockerfile·dockerfile
FROM python:3.12-slim

WORKDIR /app

# Copy dependency manifest first (cache-friendly)
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy the rest of the app
COPY . .

EXPOSE 8000

CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
Build 와 run·bash
# Build (the . is the build context)
docker build -t myapi:1.0 .

# Run
docker run -d -p 8000:8000 --name api myapi:1.0

# Verify
curl http://localhost:8000/docs

External links

Exercise

본인의 작은 프로젝트 (Python, Node, Go) 골라. FROM, WORKDIR, COPY, RUN, EXPOSE, CMD 만 써서 6줄짜리 Dockerfile 작성. Build 하고 run 해. Dockerfile 이랑 실행 중인 container 에 대한 동작하는 curl 캡처.

Progress

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

댓글 0

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

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