打開Launchpad並定位到docker Quickstart Terminal圖標.docker
點擊Docker Quickstart Terminal圖標, 打開一個窗口.json
將光標定位到Docker Quickstart Terminal窗口app
輸入docker images命令來查看當前的鏡像列表:less
$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
docker-whale latest 7d9495d03763 38 minutes ago 273.7 MB
docker/whalesay latest fb434121fc77 4 hours ago 247 MB
hello-world latest 91c95931e552 5 weeks ago 910 B
找到docker-whale鏡像的image idui
在這個例子中, id是7d9495d03763命令行
值得注意的是, Hub庫顯示的是庫的名稱而不是命名空間. 對於Docker Hub將docker-whale鏡像與Docker Hub賬戶相關聯後, 你須要爲它重命名爲YOUR_DOCKERHUB_USERNAME/docker-whale. 您的賬戶名稱會在Docker Hub中顯示鏡像的命名空間. 你會在下一步標記鏡像中作到這一點.orm
使用IMAGE ID和docker tag命令來標記docker-whale鏡像.ssl
命令看來起來像這樣子:rem
$ docker tag 7d9495d03763 maryatdocker/docker-whale:latest
固然你的帳戶名稱應該是你本身的, 因此, 你要在這個命令中使用本身的帳戶名稱和鏡像ID, 而後按回車.
再次輸入docker images命令來查看當前的鏡像列表:
$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
docker-whale latest 7d9495d03763 38 minutes ago 273.7 MB
docker/whalesay latest fb434121fc77 4 hours ago 247 MB
hello-world latest 91c95931e552 5 weeks ago 910 B
使用docker login命令從命令行登錄Docker Hub
登錄命令的格式是這樣的:
docker login --username=yourhubusername --email=youremail@company.com
當命令返回響應是, 輸入你的密碼並按回車, 因此, 像這樣:
$ docker login --username=maryatdocker --email=mary@docker.com
Password:
WARNING: login credentials saved in C:\Users\sven.docker\config.json
Login Succeeded
輸入docker push命令來推送你的鏡像到Hub庫
$ docker push maryatdocker/docker-whale
The push refers to a repository [maryatdocker/docker-whale] (len: 1)
7d9495d03763: Image already exists
c81071adeeb5: Image successfully pushed
eb06e47a01d2: Image successfully pushed
fb434121fc77: Image successfully pushed
5d5bd9951e26: Image successfully pushed
99da72cfe067: Image successfully pushed
1722f41ddcb5: Image successfully pushed
5b74edbcaa5b: Image successfully pushed
676c4a1897e6: Image successfully pushed
07f8e8c5e660: Image successfully pushed
37bea4ee0c81: Image successfully pushed
a82efea989f9: Image successfully pushed
e9e06b06e14c: Image successfully pushed
Digest: sha256:ad89e88beb7dc73bf55d456e2c600e0a39dd6c9500d7cd8d1025626c4b985011
返回你在Docker Hub的頁面查看你的新鏡像
第二步: 拉取新鏡像
在這最後一節,你會拉取你剛剛推送到Docker Hub上的鏡像。在此以前, 你須要從本地計算機中刪除原始鏡像. 若是你沒有刪除, Docker不會從Hub上拉取鏡像 - 爲何這樣呢?由於兩個圖像是相同的.
將光標定位到Docker Quickstart Terminal窗口
輸入docker images來列出你當前在本地的鏡像列表
$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
maryatdocker/docker-whale latest 7d9495d03763 5 minutes ago 273.7 MB
docker-whale latest 7d9495d03763 2 hours ago 273.7 MB
docker/whalesay latest fb434121fc77 5 hours ago 247 MB
hello-world latest 91c95931e552 5 weeks ago 910 B
爲了測試成功,你須要從本地系統中刪除了鯨和泊塢窗鯨圖像。刪除maryatdocker/docker-whale 和 docker-whale. 它們迫使下次使用docker pull時, Docker從Hub庫中獲取鏡像.
使用docker rmi刪除maryatdocker/docker-whale和docker-whale鏡像.
你能夠使用鏡像ID或者名稱刪除
$ docker rmi -f 7d9495d03763
$ docker rmi -f docker-whale
使用docker run命令從你的Hub庫中拉取並加載新的鏡像
docker run yourusername/docker-whale
因爲鏡像再也不在本地系統上,Dokcer要下載它。
$ docker run maryatdocker/docker-whale
Unable to find image 'maryatdocker/docker-whale:latest' locally
latest: Pulling from maryatdocker/docker-whale
eb06e47a01d2: Pull complete
c81071adeeb5: Pull complete
7d9495d03763: Already exists
e9e06b06e14c: Already exists
a82efea989f9: Already exists
37bea4ee0c81: Already exists
07f8e8c5e660: Already exists
676c4a1897e6: Already exists
5b74edbcaa5b: Already exists
1722f41ddcb5: Already exists
99da72cfe067: Already exists
5d5bd9951e26: Already exists
fb434121fc77: Already exists
Digest: sha256:ad89e88beb7dc73bf55d456e2c600e0a39dd6c9500d7cd8d1025626c4b985011
Status: Downloaded newer image for maryatdocker/docker-whale:latest
________________________________________
/ Having wandered helplessly into a | blinding snowstorm Sam was greatly |
| relieved to see a sturdy Saint Bernard |
| dog bounding toward him with the |
| traditional keg of brandy strapped to |
| his collar. |
| |
| "At last," cried Sam, "man's best |
friend -- and a great big dog, too!" /
----------------------------------------
## .
## ## ## ==
## ## ## ## ===
/""""""""""""""""/ ===
~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ / ===- ~~~
___ o /
/
____/