from

1. Github Container Registry

9 月 1 日,GitHub 宣布 Github Container Registry 开始公测,测试期间提供免费、无限容量的 Docker 镜像仓库服务。
再也不用担心,docker.io 一言不合清理镜像了。真好真香!
GitHub 正在以托管代码仓库为切入点,逐步覆盖整个研发工具链,打造一站式 DevOps 平台。项目管理有 Issues 、Projects,包管理有 Packages,CI 有 Actions,知识管理有 Wiki ,覆盖面越来越广。
接下来应该就是 CD 部分了,提供容器托管服务是个不错的选择。@GitHub

2. 推送第一个镜像

下面我们来试试推送一个镜像。

2.1 创建登陆 Token

直接使用 GitHub 的账户密码推送镜像会提示错误:

  1. unauthorized: Your token has not been granted the required scopes to execute this query. The 'id' field requires one of the following scopes: ['read:packages'], but your token has only been granted the: [''] scopes. Please modify your token's scopes at: https://github.com/settings/tokens.

Github Container registry 需要使用 https://github.com/settings/tokens/new 页面创建的 Token 作为密码才可以推送镜像。
打开上面的链接,勾选 write:packages 和 read:packages ,repo 会自动选中,创建 Token。
image.png
image.png
下面以 XXX 代指这里的 Token 值。

2.2 镜像推送

  • 登陆(WARNING提示token会保存在/root/.docker/config.json,如不是自己电脑记得要删除) ```bash echo “XXX” | docker login ghcr.io -u shaowenchen —password-stdin

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

  1. - 新建 Tag
  2. 查看镜像列表
  3. ```bash
  4. docker images
  5. mysql 8.0.11 5dbe5b6313e1 2 years ago 445MB

新建 Tag

docker tag 5dbe5b6313e1 ghcr.io/shaowenchen/mysql
  • 推送 ```bash docker push ghcr.io/shaowenchen/mysql

The push refers to repository [ghcr.io/shaowenchen/mysql] ae2d2cded00e: … latest: digest: sha256:d98a807f255bd60cd7807af6a11f94cd2456a2908a12adb3737088473c1625a2 size: 2828

这样就完成了镜像的推送。但是镜像并不是每个人都可以 pull ,下面接着来看下镜像的可见性管理。
<a name="SfYiR"></a>
### 2.3 可见性管理
推送完成镜像之后,在个人的主页 packages 标签页下面,可以看到镜像列表。<br />![image.png](https://cdn.nlark.com/yuque/0/2021/png/2678153/1637050413231-75134770-e4cd-47dc-b18c-f0e3d44f3bea.png#clientId=u1ac2e263-5a5f-4&crop=0&crop=0&crop=1&crop=1&from=paste&id=uf93ed376&margin=%5Bobject%20Object%5D&name=image.png&originHeight=708&originWidth=1340&originalType=url&ratio=1&rotation=0&showTitle=false&size=185978&status=done&style=none&taskId=u46e96572-6402-4abd-a158-a619cf4cae1&title=)<br />默认推送的镜像是 Private ,只有授权的账户才可以 pull 。而 Public 镜像可以匿名 pull ,没有限制。

- Private

![image.png](https://cdn.nlark.com/yuque/0/2021/png/2678153/1637050413111-a1990c72-9ef2-40ae-95e4-6e2f3ecbbcab.png#clientId=u1ac2e263-5a5f-4&crop=0&crop=0&crop=1&crop=1&from=paste&id=u00e5ab25&margin=%5Bobject%20Object%5D&name=image.png&originHeight=674&originWidth=1081&originalType=url&ratio=1&rotation=0&showTitle=false&size=98056&status=done&style=none&taskId=u104b0571-aa40-4bcd-8c6d-f9905d384d5&title=)<br />![image.png](https://cdn.nlark.com/yuque/0/2021/png/2678153/1637050412808-5273f25c-321a-45db-8556-bd1ea1709a7b.png#clientId=u1ac2e263-5a5f-4&crop=0&crop=0&crop=1&crop=1&from=paste&id=u16c79703&margin=%5Bobject%20Object%5D&name=image.png&originHeight=655&originWidth=1032&originalType=url&ratio=1&rotation=0&showTitle=false&size=81924&status=done&style=none&taskId=u57c903cb-697e-4082-ac7c-7d54b06084c&title=)<br />在 Private 镜像的 Packages settings 页面,可以将 Private 镜像改为 Public ,还可以进行授权的管理 Manage Access。

- Public

![image.png](https://cdn.nlark.com/yuque/0/2021/png/2678153/1637050413823-886edef3-03c9-442c-8021-95e2d710f06f.png#clientId=u1ac2e263-5a5f-4&crop=0&crop=0&crop=1&crop=1&from=paste&id=ud7a20818&margin=%5Bobject%20Object%5D&name=image.png&originHeight=673&originWidth=1046&originalType=url&ratio=1&rotation=0&showTitle=false&size=95540&status=done&style=none&taskId=u3cfbe9c5-d169-43a9-acde-f60a88171b6&title=)<br />![image.png](https://cdn.nlark.com/yuque/0/2021/png/2678153/1637050414454-42070dfe-9778-45c4-9293-ee5b18c33878.png#clientId=u1ac2e263-5a5f-4&crop=0&crop=0&crop=1&crop=1&from=paste&id=u275f7270&margin=%5Bobject%20Object%5D&name=image.png&originHeight=608&originWidth=1034&originalType=url&ratio=1&rotation=0&showTitle=false&size=70272&status=done&style=none&taskId=ub829f808-6169-4138-b900-80bbbb4e608&title=)<br />需要注意的是在 Public 镜像的 Packages settings 页面,无法修改镜像的可见性,只能删除镜像。
<a name="vBWpF"></a>
### 2.4 容器关联仓库
个人的主页 packages 标签页下面,点击想要管理的镜像,点击Connect Repostitory,选择要关联的仓库就可以了<br />![image.png](https://cdn.nlark.com/yuque/0/2021/png/2678153/1637051069274-339d4b32-66a9-4b42-a5b6-f2685fecb83e.png#clientId=u4f9646cd-3ebd-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=815&id=u38234f9d&margin=%5Bobject%20Object%5D&name=image.png&originHeight=815&originWidth=721&originalType=binary&ratio=1&rotation=0&showTitle=false&size=51452&status=done&style=none&taskId=uf2771b3e-3ab2-4399-9a29-a486fd526ee&title=&width=721)
<a name="QDsUn"></a>
## 3. 与 docker.pkg.github.com 的区别
ghcr.io 与 docker.pkg.github.com 类似,都是提供镜像仓库服务,使用一样的鉴权方式。但是也有些不同:

- 维度不同

ghcr.io 针对的是账户维度,是以账户为基本对象提供的服务。而 docker.pkg.github.com 针对的是仓库维度,是以仓库为基本对象提供的服务。

- 管理粒度不同

![image.png](https://cdn.nlark.com/yuque/0/2021/png/2678153/1637050414515-536621c9-3be9-42a9-925c-5fda4618fc52.png#clientId=u1ac2e263-5a5f-4&crop=0&crop=0&crop=1&crop=1&from=paste&id=u2ecc6647&margin=%5Bobject%20Object%5D&name=image.png&originHeight=690&originWidth=1536&originalType=url&ratio=1&rotation=0&showTitle=false&size=128629&status=done&style=none&taskId=ua74f0071-2c35-406d-a92d-f5c4a5fdecf&title=)<br />docker.pkg.github.com 中的镜像不允许直接删除,只能通过删除仓库的方式,关联删除镜像。<br />而在 ghcr.io 中,可以直接完全管理镜像。

- 镜像格式不同

对比一下两者的镜像格式:
```bash
docker.pkg.github.com/OWNER/REPOSITORY/IMAGE-NAME
ghcr.io/OWNER/IMAGE-NAME

docker.pkg.github.com 镜像格式形如 docker.pkg.github.com/shaowenchen/pipeline-test/mysql ,在名字中会带上仓库名。而 ghcr.io 提供的 ghcr.io/shaowenchen/mysql 与其他镜像仓库的命名规范更加一致。

4. 参考