<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自带的镜像“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
运行“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基本的工做原理。