首先登录到GitHub

docker login ghcr.io
docker login ghcr.io
➜  /workspace git:(main) docker login ghcr.io
Username: 这里输入你的Github用户名
Password: 这里输入你的GitHub令牌密钥
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

在准备上传镜像之前,需要为镜像设置标签。运行以下命令:

docker tag yourusername/your-repo-name:tag ghcr.io/yourusername/your-repo-name:tag

例如:

➜  /workspace git:(main) docker tag 9655e88780e7 ghcr.io/liangshao666/git-cnb:latest

推送镜像到 GitHub

现在,你可以使用以下命令将镜像推送到 GitHub:

docker push ghcr.io/yourusername/your-repo-name:tag

例如:

➜  /workspace git:(main) docker push ghcr.io/liangshao666/git-cnb:latest
The push refers to repository [ghcr.io/liangshao666/git-cnb]
c176ccb80c9c: Pushed 
9b95662277c7: Pushed 
b399b189b470: Pushed 
7bc7107bcdec: Pushed 
0499fc56f5e2: Pushed 
latest: digest: sha256:9ed31deccb733c4e6efed08b4a68c25f55e1566b31666e73d784bc7445a1555c size: 1366

参考链接:

docker push 推送到github
docker 镜像上传到GitHub