C.W.K.
Stream
Lesson 03 of 13 · published

Docker build & push

~13 min · docker, ghcr, registry

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

기본 컨테이너 pipeline

표준 'Docker image 빌드해서 registry 에 push' 모양은 action 셋 사용: docker/setup-buildx-action (multi-platform 지원), docker/login-action (registry 인증), docker/build-push-action (빌드 + cache 와 함께 push).

어디에 push

  • ghcr.io (GitHub Container Registry) — 최선의 default. GITHUB_TOKEN 으로 인증; 같은 권한 모델.
  • Docker Hub — 역사적 default; free tier 에 image rate limit.
  • ECR / Artifact Registry / ACR — AWS / GCP / Azure 에 있고 청구서 하나 원할 때.

쓸 만한 tag 컨벤션

  • :<sha-7> — 모든 image 가 Git commit 으로 추적 가능.
  • :v1.4.2 — release 버전, tag push 에만.
  • :latest — 이동 포인터; production manifest 에 사용 금지.
  • :edge — main branch tip; staging 용.

Build cache

GitHub Actions cache backend 사용: cache-from: type=gha, cache-to: type=gha, mode=max. 별도 registry cache 설정 없이 run 간 layer caching.

Code

Multi-arch + cache 와 함께 GHCR build + push·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

Docker 화된 서비스 있으면 CI 를 SHA + branch tag 로 ghcr.io 에 push. docker pull ghcr.io/<org>/<repo>:<sha> 로 image 로컬 pull 하고 실행 확인.

Progress

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

댓글 0

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

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