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,636評論 15 147
  • 以下原文轉載于(https://docs.docker.com/docker-for-mac/)(想找中文版的最新...
    Veekend閱讀 7,645評論 0 17
  • 注意: 該 Docker 版本為了支持 Docker 機,于是不再支持 Boot2Docker 命令行。使用 Do...
    提莫隊長1234閱讀 4,655評論 0 8
  • 假期到來,最想做的是睡覺,第一件事就是刪除鬧鈴,期盼睡他個昏天黑地!什么也不想! 假期前三天,沒錯,天還沒亮又醒了...
    薇薇_24ee閱讀 258評論 0 3
  • 生病的人,大概會更加脆弱。 班車上,一個人坐在后排,聽著音樂,本打算給自己補個覺,可音樂聽著聽著就有了你的痕跡。七...
    盼噠仔閱讀 271評論 0 1