0.0.准備工作
- 在阿里雲上開通"容器鏡像服務"
0.1.占位符解釋
😂
{
"{YourNamespace}":"阿里雲容器鏡像服務中的命名空間,具體位置 → 阿里雲 / 容器鏡像服務 / 實例列表 / 鏡像倉庫 / 倉庫管理 / 命名空間",
"{YourRepoName}":"阿里雲容器鏡像服務中的鏡像倉庫,具體位置 → 阿里雲 / 容器鏡像服務 / 實例列表 / 鏡像倉庫 / 倉庫管理 / 鏡像倉庫",
}
1.登錄阿里雲Docker Registry
$ docker login --username=username@aliyun registry.aliyuncs.com
Password:
WARNING! Your password will be stored unencrypted in /home/username/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
2.將鏡像推送到Registry
#[ImageId]就是你服務器上的鏡像的Id , 可以先使用"docker images"查詢一下要推送的鏡像Id
#標記本地鏡像 , 將其歸入阿里雲Docker倉庫 .
$ docker tag [ImageId] registry.aliyuncs.com/{YourNamespace}/{YourRepoName}:latest
#將本地的鏡像上傳到鏡像倉庫 , 要先登陸到鏡像倉庫 .
$ docker push registry.aliyuncs.com/{YourNamespace}/{YourRepoName}:latest
#以下為輸出內容 . . .
The push refers to repository [registry.aliyuncs.com/{YourNamespace}/test]
xxxxxxxxxxxx: Pushed
xxxxxxxxxxxx: Pushed
xxxxxxxxxxxx: Pushed
xxxxxxxxxxxx: Pushed
xxxxxxxxxxxx: Pushed
xxxxxxxxxxxx: Pushed
xxxxxxxxxxxx: Pushed
xxxxxxxxxxxx: Pushed
xxxxxxxxxxxx: Pushed
xxxxxxxxxxxx: Pushed
latest: digest: sha256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx size: 2420
3.從阿里雲Docker容器中拉取鏡像
#如果倉庫類型為"私有"的話,需要先登錄,否則報錯 .
$ docker pull registry.aliyuncs.com/{YourNamespace}/{YourRepoName}:latest
#以下為輸出內容 . . .
Error response from daemon: pull access denied for registry.aliyuncs.com/{YourNamespace}/test, repository does not exist or may require 'docker login': denied: requested access to the resource is denied
#如果倉庫類型為"私有"的話,登錄之后 , 再次拉取
$ docker pull registry.aliyuncs.com/{YourNamespace}/{YourRepoName}:latest
#以下為輸出內容 . . .
latest: Pulling from {YourNamespace}/test
xxxxxxxxxxxx: Pull complete
xxxxxxxxxxxx: Pull complete
xxxxxxxxxxxx: Pull complete
xxxxxxxxxxxx: Pull complete
xxxxxxxxxxxx: Pull complete
xxxxxxxxxxxx: Pull complete
xxxxxxxxxxxx: Pull complete
xxxxxxxxxxxx: Pull complete
xxxxxxxxxxxx: Pull complete
xxxxxxxxxxxx: Pull complete
Digest: sha256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Status: Downloaded newer image for registry.aliyuncs.com/{YourNamespace}/{YourRepoName}:latest
registry.aliyuncs.com/{YourNamespace}/{YourRepoName}:latest