【原文链接】
(1)首先确认本机没有 hello-world 镜像
[root@redrose2100 ~]# docker images | grep hello-world
[root@redrose2100 ~]#
(2)然后执行docker run hello-world 运行hello-world容器,回显如下
[root@redrose2100 ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:2498fce14358aa50ead0cc6c19990fc6ff866ce72aeb5546e1d59caac3d0d60f
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:
https://docs.docker.com/get-started/
[root@redrose2100 ~]#
(3)docker容器的启动流程如下
- (1)执行docker run hello-world命令后,docker命令会在本机寻找名为hello-world的镜像,比如这里发现本地没有
- (2)此时docker 就会去docker hub上搜索名称为hello-world的镜像,比如这里在docker hub上搜索到了hello-world的镜像
- (3)从docker hub上下载名称为hello-world的镜像到本地
- (4)使用hello-world镜像执行此docker
(4)第二次执行docker run hello-world运行容器
[root@redrose2100 ~]# 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/
[root@redrose2100 ~]#
可以发现此时,会使用本地已经存在的镜像。而不会再去docker hub 上下载镜像了