본문 바로가기
C.W.K.
Stream
Lesson 03 of 13 · published

Docker 빌드 & 푸시

~13 min · docker, ghcr, registry

Level 0견습생
0 XP0/101 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

기본 컨테이너 파이프라인

도커 이미지를 빌드해서 레지스트리에 푸시하는 표준 패턴은 액션 세트를 활용해. docker/setup-buildx-action로 멀티 플랫폼을 지원하고, docker/login-action으로 레지스트리 인증을 처리한 다음, docker/build-push-action으로 빌드와 캐시를 함께 푸시하면 돼.

어디에 푸시할까

  • ghcr.io (GitHub Container Registry) — 가장 추천하는 기본값이야. GITHUB_TOKEN으로 인증하고 기존 권한 모델을 그대로 쓸 수 있어.
  • Docker Hub — 과거부터 쓰던 기본값이지만, 무료 등급에서는 이미지 요청에 제한이 있어.
  • ECR / Artifact Registry / ACR — AWS, GCP, Azure 환경에서 청구를 하나로 묶고 싶을 때 써.

유용한 태그 컨벤션

  • :<sha-7> — 모든 이미지를 깃 커밋으로 추적할 수 있어.
  • :v1.4.2 — 릴리스 버전이며, 태그를 푸시할 때만 써.
  • :latest — 계속 움직이는 포인터라서 프로덕션 매니페스트에는 쓰면 안 돼.
  • :edge — 메인 브랜치의 최신 상태를 가리키며, 스테이징 환경에 써.

빌드 캐시

GitHub Actions 캐시 백엔드를 사용해: cache-from: type=gha, cache-to: type=gha, mode=max. 별도로 레지스트리 캐시를 설정하지 않아도 실행마다 레이어 캐싱이 가능해.

Code

멀티 아키텍처와 캐시를 곁들여 GHCR에 빌드 및 푸시하기·yaml
name: docker
on:
  push:
    branches: [main]
    tags: ['v*.*.*']
  pull_request: {}

permissions:
  contents: read
  packages: write       # to push to ghcr.io
  id-token: write       # for OIDC if pushing to AWS too

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: docker/setup-qemu-action@v3
      - uses: docker/setup-buildx-action@v3
      - uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - uses: docker/metadata-action@v5
        id: meta
        with:
          images: ghcr.io/${{ github.repository }}
          tags: |
            type=ref,event=branch
            type=ref,event=pr
            type=semver,pattern={{version}}
            type=sha,prefix=,format=short
      - uses: docker/build-push-action@v6
        with:
          context: .
          platforms: linux/amd64,linux/arm64
          push: ${{ github.event_name != 'pull_request' }}
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}
          cache-from: type=gha
          cache-to: type=gha,mode=max

External links

Exercise

도커로 만든 서비스가 있다면 CI에서 SHA와 브랜치 태그로 ghcr.io에 푸시해 봐. docker pull ghcr.io/<org>/<repo>:<sha>로 이미지를 로컬로 가져와서 실행해 확인해.

Progress

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

댓글 0

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

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