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、对应镜像、命令行、创建时间、状态、端口号和名称。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Docker — 云时代的程序分发方式 要说最近一年云计算业界有什么大事件?Google Compute Engi...
    ahohoho阅读 15,661评论 15 147
  • 以下原文转载于(https://docs.docker.com/docker-for-mac/)(想找中文版的最新...
    Veekend阅读 7,674评论 0 17
  • 注意: 该 Docker 版本为了支持 Docker 机,于是不再支持 Boot2Docker 命令行。使用 Do...
    提莫队长1234阅读 4,660评论 0 8
  • 假期到来,最想做的是睡觉,第一件事就是删除闹铃,期盼睡他个昏天黑地!什么也不想! 假期前三天,没错,天还没亮又醒了...
    薇薇_24ee阅读 267评论 0 3
  • 生病的人,大概会更加脆弱。 班车上,一个人坐在后排,听着音乐,本打算给自己补个觉,可音乐听着听着就有了你的痕迹。七...
    盼哒仔阅读 275评论 0 1