GitHub Container Registry에 도커 이미지 Push 하기

![package.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/144058/398dc030-bdf0-ec13-8807-8bde61bd9e7f.png)
## TL;DR
> [Docker Hub 정책 변경](https://www.44bits.io/ko/post/news--docker-hub-image-retention-limit)으로 오는 11월1일부터 지난 6개월간 Push나 Pull이 없던 이미지는 삭제된다고 합니다.
> 백업 차원에서 [GitHub의 Packages](https://github.com/features/packages)에 도커 이미지를 Push 해두면 어떨까요? 

## 준비물
- GitHub 계정
- [GitHub's Personal Access Token](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token)
    - GitHub Profile > Settings > Developer settings > Personal access tokens > Generate new token
        - `write:packages` `read:packages`  `delete:packages` `repo` 체크 > Generate token  
![001.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/144058/9f848200-82f0-f997-31bd-79811a2c681a.png)
![002.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/144058/2f09a6bb-ded8-96d7-a3fd-63cf285e921b.png)
![003.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/144058/b5bd1c14-077f-43fe-86a8-2d37ab57a1c0.png)

## 실행하기
### [GitHub Container Registry](https://github.blog/2020-09-01-introducing-github-container-registry/) 로그인
```bash
$  docker login ghcr.io -u <github_id> 
Password: #<Pesonal Access Token> 입력
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded
```
### GitHub Container Registry에 이미지 푸시
```bash
$ docker images -a
REPOSITORY        TAG        IMAGE ID        CREATED        SIZE
jenkins/jenkins   lts        135a0d19f757    5 weeks ago    667MB

# 이미지 태그하기
$ docker tag 135a0d19f757 ghcr.io/<github_id>/jenkins:lts

# GitHub에 이미지 푸시하기
$ docker push ghcr.io/<github_id>/jenkins:lts
The push refers to repository [ghcr.io/<github_id>/jenkins]
127451aea177: Pushed
f5bcfae65e8c: Pushed
687e70c08de0: Pushed
97228bebcea6: Pushed
5ea28e96a7c4: Pushed
09df571b2d1a: Pushed
1621b831e01c: Pushed
c2210d8051b3: Pushed
96706081cc19: Pushed
053d23f0bdb8: Pushed
a18cfc771ac0: Pushed
9cebc9e5d610: Pushed
d81d8fa6dfd4: Pushed
bd76253da83a: Pushed
e43c0c41b833: Pushed
01727b1a72df: Pushed
69dfa7bd7a92: Pushed
4d1ab3827f6b: Pushed
7948c3e5790c: Pushed
lts: digest: sha256:c2201520b3ee92e3d84ad8705167f7fd9b431a90e16d31a1b4407a547c3bc294 size: 4299
```

## GitHub에서 확인하기
개인 Profile > Packages 에서 확인 가능합니다. 
※ 현재는 개인 Profile > Packages 로만 접근할 수 있는 것 같습니다.
![005.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/144058/4b41b540-96de-d5fe-69bc-23331e785509.png)

공개/비공개 설정이 가능합니다. `Public`과 `Private` 
개인 Profile > Packages > Edit package > Package settings > Make Public
![013.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/144058/6d1b1975-a75a-082b-7ffe-e9a17fb58e12.png)
![012.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/144058/a7cb2cff-8174-62eb-cceb-8513fa2595dd.png)

이미지 버전을 지울 수도 있습니다.
개인 Profile > Packages > Settings > Edit package > View all versions
![011.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/144058/f6182da2-9614-b169-6a20-870fc7cae403.png)
![010.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/144058/2b237f5c-dc85-97b1-b8b7-264ea991d2df.png)

## 참고링크
- https://www.44bits.io/ko/post/news--docker-hub-image-retention-limit
- https://qiita.com/zembutsu/items/1effae6c39ceae3c3d0a
- https://qiita.com/zembutsu/items/e92a2e2f46b147e5a206
- https://github.blog/2020-09-01-introducing-github-container-registry/