docker 标记和推送镜像
打开Launchpad并定位到docker Quickstart Terminal图标.
点击Docker Quickstart Terminal图标, 打开一个窗口.
将光标定位到Docker Quickstart Terminal窗口
输入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-whale镜像的image id
在这个例子中, id是7d9495d03763
值得注意的是, Hub库显示的是库的名称而不是命名空间. 对于Docker Hub将docker-whale镜像与Docker Hub帐户相关联后, 你需要为它重命名为YOUR_DOCKERHUB_USERNAME/docker-whale. 您的帐户名称会在Docker Hub中显示镜像的命名空间. 你会在下一步标记镜像中做到这一点.
使用IMAGE ID和docker tag命令来标记docker-whale镜像.
命令看来起来像这样子:
$ 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 __/
\ \ __/
\____\______/