在这一部分, 你会标记, 推送你的docker-whale镜像到你刚才新建好的Hub库中. 当你作好只好, 你能够拉去你的新镜像来测试你的Hub库是否正常.docker
If you don’t already have a terminal open, open one now:json
打开Launchpad并定位到Docker Quickstart Terminal图标.app
点击Docker Quickstart Terminal图标, 打开一个窗口.less
将光标定位到Docker Quickstart Terminal窗口测试
输入docker images
命令来查看当前的镜像列表:ui
$ docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE docker-whale latest 7d9495d03763 38 minutes ago 273.7 MB <none> <none> 5dac217f722c 45 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
spa
在这个例子中, id是7d9495d03763
.net
值得注意的是, Hub库显示的是库的名称而不是命名空间. 对于Docker Hub将docker-whale镜像与Docker Hub账户相关联后, 你须要为它重命名为YOUR_DOCKERHUB_USERNAME/docker-whale
. 您的账户名称会在Docker Hub中显示镜像的命名空间. 你会在下一步标记镜像中作到这一点.命令行
使用IMAGE ID
和docker tag
命令来标记docker-whale镜像.code
命令看来起来像这样子:
固然你的帐户名称应该是你本身的, 因此, 你要在这个命令中使用本身的帐户名称和镜像ID, 而后按回车.
$ docker tag 7d9495d03763 maryatdocker/docker-whale:latest
再次输入docker images
命令来查看当前的镜像列表:
$ docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE docker-whale latest 7d9495d03763 38 minutes ago 273.7 MB <none> <none> 5dac217f722c 45 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 <none> <none> 5dac217f722c 5 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 __/ \ \ __/ \____\______/
下一步去哪里
你已经作了不少,你已经作了全部的如下基本Docker任务。
不过至此, 你只是接触了Docker全部能作的基本内容. 转到下一个页面, 了解更多信息.