06 - 分析docker run hello-world

在前面的《Centos7中安装及验证Docker》《Windows8中安装及验证Docker》两篇文章中都有看到:docker run hello-word,为了更深入的认识Docker,在这篇文章中着重讲解一下这句命令的作用和工作流程,从而更加深刻的认识Docker的工作原理。

  • 输入启动容器命令:
docker run hello-word

将会出现:

C:\Users\zsl-pc>docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world

c04b14da8d14: Pull complete
Digest: sha256:0256e8a36e2070f7bf2d0b0763dbabdd67798512411de4cdcf9431a1feb60fd9
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker Hub account:
 https://hub.docker.com

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

说明:

Unable to find image 'hello-world:latest' locally:表示没有在本地找到镜像hello-world:latest

:latest:是指版本号或标记,同一个应用程序可能有多个版本或多个标记,我们可以通过修改latest来修改对应的版本信息。

latest: Pulling from library/hello-world:正在拉取镜像,也就是将该镜像下载到本地

c04b14da8d14: Pull complete:下载完成。

Hello from Docker!开始到最后就是hello-world这个镜像所做的工作,它只是输出了这样几句话。


当再次输入:docker run hello-world时,将不再出现类似Unable to find image 'hello-world:latest' locallypulling的字样,因为该镜像已经在本地存在,只需要直接run就行。

  • 查看现有镜像
C:\Users\zsl-pc>docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              c54a2cc56cbb        4 months ago        1.848 kB

在这里可以看到这些镜像的仓库、标记、id、创建时间、大小等信息

  • 查看全部容器
C:\Users\zsl-pc>docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS
        NAMES
fcee30d727b4        hello-world         "/hello"            14 minutes ago      Exited (0) 13 minutes ago
        elated_feynman
e2eb5d0a9f96        hello-world         "/hello"            18 minutes ago      Exited (0) 16 minutes ago
        cranky_engelbart

在这里可以看到所有已经运行(过)的容器,包括:容器Id、对应镜像、命令行、创建时间、状态、端口号和名称。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值