/엔지니어/Docker / 컨테이너/사설 Docker 레지스트리 — Harbor · A
Docker / 컨테이너중급UbuntuDebianCentOSdockerregistryharbor

사설 Docker 레지스트리 — Harbor · AWS ECR · GHCR 운영

Harbor 셀프호스팅 레지스트리 구축, AWS ECR, GitHub Container Registry에 이미지를 push/pull하는 방법과 Kubernetes에서 사설 레지스트리를 사용하는 패턴을 설명합니다.

왜 사설 레지스트리인가?

  • 외부 공개 불가한 이미지 관리
  • Docker Hub rate limit 우회
  • 빌드 속도 개선 (내부 네트워크)
  • 취약점 스캔·접근 제어 통합

1. Harbor — 셀프호스팅 레지스트리

Bash
# Docker Compose로 Harbor 설치
curl -LO https://github.com/goharbor/harbor/releases/latest/download/harbor-online-installer.tgz
tar xzf harbor-online-installer.tgz
cd harbor

# harbor.yml 설정
cp harbor.yml.tmpl harbor.yml
# hostname, https.certificate, https.private_key 수정

# 설치
sudo ./install.sh --with-trivy    # Trivy 이미지 스캔 포함

로그인 및 이미지 push:

Bash
docker login harbor.example.com
docker tag myapp:latest harbor.example.com/myproject/myapp:latest
docker push harbor.example.com/myproject/myapp:latest
docker pull harbor.example.com/myproject/myapp:latest

2. AWS ECR (Elastic Container Registry)

Bash
# 레지스트리 생성
aws ecr create-repository   --repository-name myapp   --region ap-northeast-2

# 레지스트리 URI 확인
aws ecr describe-repositories   --query 'repositories[0].repositoryUri'   --output text

# 로그인 (토큰 12시간 유효)
aws ecr get-login-password --region ap-northeast-2   | docker login --username AWS     --password-stdin 123456789012.dkr.ecr.ap-northeast-2.amazonaws.com

# 이미지 태그 + push
REGISTRY=123456789012.dkr.ecr.ap-northeast-2.amazonaws.com
docker tag myapp:latest ${REGISTRY}/myapp:latest
docker push ${REGISTRY}/myapp:latest

# 이미지 목록
aws ecr list-images --repository-name myapp

# 오래된 이미지 자동 삭제 정책
aws ecr put-lifecycle-policy   --repository-name myapp   --lifecycle-policy-text '{
    "rules": [{
      "rulePriority": 1,
      "selection": {
        "tagStatus": "untagged",
        "countType": "sinceImagePushed",
        "countUnit": "days",
        "countNumber": 7
      },
      "action": {"type": "expire"}
    }]
  }'

3. GitHub Container Registry (GHCR)

Bash
# PAT 생성: GitHub → Settings → Developer settings → Personal access tokens
# 권한: write:packages, read:packages, delete:packages

# 로그인
echo $GITHUB_TOKEN | docker login ghcr.io -u USERNAME --password-stdin

# 이미지 push
docker tag myapp:latest ghcr.io/USERNAME/myapp:latest
docker push ghcr.io/USERNAME/myapp:latest

GitHub Actions에서:

YAML
- name: Login to GHCR
  uses: docker/login-action@v3
  with:
    registry: ghcr.io
    username: ${{ github.actor }}
    password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
  uses: docker/build-push-action@v5
  with:
    push: true
    tags: ghcr.io/${{ github.repository }}:latest

Kubernetes에서 사설 레지스트리 사용

Bash
# imagePullSecret 생성
kubectl create secret docker-registry regcred   --docker-server=harbor.example.com   --docker-username=admin   --docker-password=Harbor12345   --namespace=default
YAML
# deployment.yaml
spec:
  template:
    spec:
      imagePullSecrets:
      - name: regcred
      containers:
      - name: myapp
        image: harbor.example.com/myproject/myapp:latest

ECR은 IRSA(IAM Role for Service Account)로 시크릿 없이 가능:

Bash
# eksctl로 IRSA 설정
eksctl create iamserviceaccount   --name ecr-access   --namespace default   --cluster my-cluster   --attach-policy-arn arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly   --approve
#docker#registry#harbor#ecr#ghcr#kubernetes
편집 안내 · Editorial Note

이 가이드는 AI 도구를 활용해 초안을 구성하고 사람이 명령어·문맥을 검토해 발행했습니다. 운영체제와 도구 버전에 따라 결과가 달라질 수 있으므로 적용 전 공식 문서를 함께 확인하세요. 오류를 발견하시면 이메일로 제보해 주세요.

질문 & 답변 (Q&A)

이 가이드에 대해 궁금한 점을 질문해보세요. 확인 후 답변드립니다.