docker入門2---docker的初體驗

<p align="center"> <img src="http://qiniu.tomxin.cn/blog/181008/0K5cbLhJGi.png?imageslim" alt="Material Render Phone"> </p>docker

<h1 align="center"><a href="http://tomxin.cn" target="_blank">Tomxin7 </a></h1>ubuntu

Simple, Interesting | 簡單,有趣bash

第一個Docker鏡像?

嘗試運行docker自帶的鏡像「hello-world」,瞭解docker鏡像的下載和啓動。<br> docker的整個生命週期有三部分組成:鏡像(image)+容器(container)+倉庫(repository)<br>app

一、查看當前鏡像ide

[root@tomxin docker]# docker images
結果應該是當前系統暫時尚未任何鏡像

二、下載「hello-world」鏡像學習

[root@tomxin docker]# docker pull hello-world
Using default tag: latest
Trying to pull repository docker.io/library/hello-world ... 
latest: Pulling from docker.io/library/hello-world
d1725b59e92d: Pull complete 
Digest: sha256:0add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9fde470971e499788
Status: Downloaded newer image for docker.io/hello-world:latest

三、再次查看鏡像<br>this

[root@tomxin docker]# docker images
REPOSITORY                 TAG                 IMAGE ID            CREATED             SIZE
docker.io/hello-world     latest              4ab4c602aa5e        5 weeks ago         1.84 kB

第一個docker容器

運行「hello-world」容器<br> 鏡像和容器的區別:容器是由鏡像實例化而來,這和咱們學習的面向對象的概念十分類似,咱們能夠把鏡像看做類,把容器看做類實例化後的對象。idea

一、查看容器spa

[root@tomxin docker] docker ps -a
應該暫時尚未容器

二、運行「hello-world」,運行成功後,docker會建立一個容器,上面輸出了hello-world這個項目運行,docker所作的工做步驟rest

[root@tomxin docker]# 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/get-started/

三、查看所有容器,能夠看到在run鏡像以後,建立了一個容器

[root@tomxin docker] docker ps -a

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS                    NAMES
b44b6c29ac29        hello-world         "/hello"                 14 minutes ago      Exited (0) 14 minutes ago

注意:若是沒有提早pull鏡像,直接運行docker run命令也是能夠的,在本地沒有找到對應鏡像,docker會自動請求遠程倉庫而且下載、啓動鏡像,下圖展現了docker基本的工做原理。 image

相關文章
相關標籤/搜索