标记(Tag),推送(Push),拉取(Pull)你自己的镜像

https://blog.csdn.net/jpiverson/article/details/50730607


目录

在这一部分, 你会标记, 推送你的docker-whale镜像到你刚才新建好的Hub库中. 当你做好只好, 你可以拉去你的新镜像来测试你的Hub库是否正常.

第一步: 标记和推送镜像

If you don’t already have a terminal open, open one now:

  1. 打开Launchpad并定位到Docker Quickstart Terminal图标.

    这里写图片描述

  2. 点击Docker Quickstart Terminal图标, 打开一个窗口.

  3. 将光标定位到Docker Quickstart Terminal窗口

  4. 输入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
  5. 找到docker-whale镜像的image id

    在这个例子中, id是7d9495d03763

    值得注意的是, Hub库显示的是库的名称而不是命名空间. 对于Docker Hub将docker-whale镜像与Docker Hub帐户相关联后, 你需要为它重命名为YOUR_DOCKERHUB_USERNAME/docker-whale. 您的帐户名称会在Docker Hub中显示镜像的命名空间. 你会在下一步标记镜像中做到这一点.

  6. 使用IMAGE IDdocker tag命令来标记docker-whale镜像.

    命令看来起来像这样子:

    这里写图片描述

    当然你的账户名称应该是你自己的, 所以, 你要在这个命令中使用自己的账户名称和镜像ID, 然后按回车.

    $ docker tag 7d9495d03763 maryatdocker/docker-whale:latest

  7. 再次输入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
  8. 使用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
  9. 输入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
  10. 返回你在Docker Hub的页面查看你的新镜像

    这里写图片描述

第二步: 拉取新镜像

在这最后一节,你会拉取你刚刚推送到Docker Hub上的镜像。在此之前, 你需要从本地计算机中删除原始镜像. 如果你没有删除, Docker不会从Hub上拉取镜像 - 为什么这样呢?因为两个图像是相同的.

  1. 将光标定位到Docker Quickstart Terminal窗口

  2. 输入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库中获取镜像.

  3. 使用docker rmi删除maryatdocker/docker-whaledocker-whale镜像.

    你可以使用镜像ID或者名称删除

    $ docker rmi -f 7d9495d03763
    $ docker rmi -f docker-whale
    • 1
    • 2
  4. 使用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所有能做的基本内容. 转到下一个页面, 了解更多信息.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值