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、對應鏡像、命令行、創建時間、狀態、端口號和名稱。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章