天天看點

Docker Hello-World鏡像運作測試

一、指令:docker run hello-world

    指令解釋:以docker用戶端指令的方式運作hello-world鏡像

指令運作結果:

hadoop@Docker:/opt/docker$ docker run hello-world
    Unable to find image 'hello-world:latest' locally
    latest: Pulling from library/hello-world
    d1725b59e92d: Pull complete
    Digest: sha256:0add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9fde470971e499788
    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.
        (amd64)
     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 ID:
     https://hub.docker.com/
     
    For more examples and ideas, visit:
      

 通過分析指令運作結果,說明docker内部的工作原理:

(1)加載本地鏡像

# 首先在本地查找'hello-world:latest'鏡像
    Unable to find image 'hello-world:latest' locally
      

 docker run一個鏡像,那麼則會以這個鏡像作為類的模闆生成一個hello-world容器執行個體,一個具體的對象。注意:該指令首先會查找本地的hello-world鏡像。

(2)從阿裡雲伺服器上拉去hello-world鏡像

latest: Pulling from library/hello-world
d1725b59e92d: Pull complete 
Digest: sha256:0add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9fde470971e499788
Status: Downloaded newer image for hello-world:latest      

(3)、運作

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

 (4)運作原理分析

Docker Hello-World鏡像運作測試

 首先,我們在docker用戶端(指令行終端視窗),執行docker指令;

用戶端回去通路我們docker所在的那台伺服器主機,實質而言主機上有一個Docker daemon主線程,它會監聽到用戶端的docker指令,它會run容器(Container),而容器又是通過鏡像生成的。如果沒有hello-world容器,它就會在本地查找hello-world鏡像,如果本地找到了就會直接生成一個hello-world容器,否則,會向阿裡雲伺服器倉庫拉去相應的鏡像;

從阿裡雲伺服器倉庫上拉取hello-world鏡像到本地,再生成容器,進而運作。

(5)docker容器終止運作

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.
    (amd64)
 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 ID:
 https://hub.docker.com/
 
For more examples and ideas, visit:
 https://docs.docker.com/get-started/
      

 輸出這段提示以後,hello world就會停止運作,容器自動終止