https://blog.csdn.net/jpiverson/article/details/50730607
目录
- 开始使用Docker
- 在OS X安装Docker
- 理解镜像(images)和容器(containers)
- 搜索&运行whalesay镜像
- 构建你自己的镜像
- 创建Docker Hub账号(account)&库(repository)
- 标记(Tag),推送(Push),拉取(Pull)你自己的镜像
在这一部分, 你会标记, 推送你的docker-whale镜像到你刚才新建好的Hub库中. 当你做好只好, 你可以拉去你的新镜像来测试你的Hub库是否正常.
第一步: 标记和推送镜像
If you don’t already have a terminal open, open one now:
打开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 <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
- 1
- 2
- 3
- 4
- 5
- 6
找到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镜像.命令看来起来像这样子:
当然你的账户名称应该是你自己的, 所以, 你要在这个命令中使用自己的账户名称和镜像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
- 1
- 2
- 3
- 4
- 5
- 6
使用
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
- 1
- 2
- 3
- 4
输入
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
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
返回你在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
- 1
- 2
- 3
- 4
- 5
- 6
- 7
为了测试成功,你需要从本地系统中删除了鲸和泊坞窗鲸图像。删除
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
- 1
- 2
使用
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 __/ \ \ __/ \____\______/
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
下一步去哪里
你已经做了很多,你已经做了所有的以下基本Docker任务。
- 安装Docker
- 在容器中运行的软件镜像
- 在Docker Hub中查找有趣的镜像
- 你自己的机器上运行镜像
- 修改镜像, 创建新的镜像并运行
- 创建Docker Hub帐户和库
- 推送你的镜像到Docker Hub与他人分享
不过至此, 你只是接触了Docker所有能做的基本内容. 转到下一个页面, 了解更多信息.