1. 程式人生 > >7、Docker Container

7、Docker Container

dea http ins output eps share iou bit tab

7.1 什麽是Container

  • 通過image創建(copy)
  • 在Image layer之上建立一個Container layer(可讀寫)
  • 類比面向對象:類和實例
  • Image負責APP的存儲和分發,Container負責運行APP

技術分享圖片

7.2 通過Image創建Container

??命令:

docker run
docker run hello-world

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:
 https://docs.docker.com/engine/userguide/

docker run啟動容器的背後

??docker run啟動容器時,docker在後臺一共做了下面這些事:

  1. 檢查本地是否存在指定的鏡像,不存在就從共有倉庫下載;
  2. 利用鏡像創建一個容器,並啟動該容器;
  3. 分配一個文件系統給容器,並在只讀的鏡像層外面掛載一層可讀寫層;
  4. 從宿主主機配置的網橋接口中橋接一個虛擬接口到容器中;
  5. 從網橋的地址池配置一個IP地址給容器;
  6. 執行用戶指定的應用程序;
  7. 執行完畢後,容器被終止。

7、Docker Container