Understand images & containers of Docker

4798 ワード

Dockerを使用する前に、build & shareの開発環境にVagrantを使用します.各Vagrant packageは完全な仮想ホストであり、1つのpackageには通常いくつかのGがある.いくつかのGのパッケージを共有して更新するのは高価なことです.
Docker世界ではVagrantpackagecontainers&imagesに分解し、この2つの概念がDocker世界全体を支えています.
  • container:シェルを剥がす最小化Linux.
  • イメージ:containerにロードされるソフトウェアです.
  • docker run helloworldを実行すると、dockerは次の3つのことをします.
  • ローカル検索hello-worldソフトウェアイメージ
  • 見つからない場合は、Docker Hubからimage
  • をダウンロードします.
  • は、imagecontainerにロードし、run
  • にロードする.
    通常、docker-machineを使用してcontainerを管理し、dockerを使用してimageを実行します.imagesはDocker Hubによって共有される.
    (Githubの利用者であれば、Docker Hubを簡単に手に入れることができます.Docker Hubについてはここでは紹介しません)
    Dockerのcontainerはどこですか?containerは殻を剥いた、最も基礎的なLinuxです.Mac OSではdocker-machineを使用してcontainerを管理しています.
    containerの作成devという名前のcontainer:docker-machine create --driver virtualbox devを作成
    ローカルcontainersの表示
    ➜  mydockerbuild  docker-machine ls
    NAME      ACTIVE   DRIVER       STATE     URL                         SWARM
    default            virtualbox   Running   tcp://192.168.99.101:2376
    dev                virtualbox   Running   tcp://192.168.99.100:2376
    

    containerステータスの表示
    ➜  mydockerbuild  docker-machine active
    dev
    ➜  mydockerbuild  docker-machine status dev
    Running
    

    containerに接続
    ➜  mydockerbuild  docker-machine ssh dev
                            ##         .
                      ## ## ##        ==
                   ## ## ## ## ##    ===
               /"""""""""""""""""\___/ ===
          ~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ /  ===- ~~~
               \______ o           __/
                 \    \         __/
                  \____\_______/
     _                 _   ____     _            _
    | |__   ___   ___ | |_|___ \ __| | ___   ___| | _____ _ __
    | '_ \ / _ \ / _ \| __| __) / _` |/ _ \ / __| |/ / _ \ '__|
    | |_) | (_) | (_) | |_ / __/ (_| | (_) | (__|   <  __/ |
    |_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_|
    Boot2Docker version 1.8.2, build master : aba6192 - Thu Sep 10 20:58:17 UTC 2015
    Docker version 1.8.2, build 0a8c2e3
    er@dev:~$ uname -a
    Linux dev 4.0.9-boot2docker #1 SMP Thu Sep 10 20:39:20 UTC 2015 x86_64 GNU/Linux
    

    Dockerのイメージは何ですか?
    docker run helloworld imageを実行
    このときdockerはrunというhello-worldというアプリケーションで、次の結果を印刷します.
    ➜  sts  docker run hello-world
    Unable to find image 'hello-world:latest' locally
    latest: Pulling from library/hello-world
    
    535020c3e8ad: Pull complete
    af340544ed62: Pull complete
    Digest: sha256:a68868bfe696c00866942e8f5ca39e3e31b79c1e50feaee4ce5e28df2f051d5c
    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:
    

    このときのhello-worldプログラムはdockerにおいてimageとなり、dockerによってcontainerの上に置かれて実行される.
    docker imagesローカルのimagesを表示
    ➜  mydockerbuild  docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
    docker-whale        latest              1935900e3705        5 hours ago         274 MB
    ubuntu              latest              91e54dfb1179        6 weeks ago         188.4 MB
    hello-world         latest              af340544ed62        8 weeks ago         960 B
    docker/whalesay     latest              fb434121fc77        4 months ago        247 MB
    

    まとめimages&containersはDockerの世界で最も基本的な概念です.imageはソフトウェアであり、containerはソフトウェアを実行するためのオペレーティングシステムである.Dockerの世界では、私たちはほとんどの時間をDockerのimagesと付き合っています.dockerは、gitと同様のメカニズムを使用してimagesを管理および共有し、dockerを使用してimagesを作成する場合、gitを使用する場合と同様である.Docker Hubの存在は、Githubgitの存在と同様に、docker imagesの共有を非常に容易にする.