helloworld 镜像 | 学习笔记

简介: 快速学习 helloworld 镜像

开发者学堂课程【Docker 快速入门:helloworld 镜像】学习笔记,与课程紧密联系,让用户快速学习知识。

课程地址:https://developer.aliyun.com/learning/course/616/detail/9393


helloworld 镜像

配置完阿里云镜像加速器之后,如图:

image.png

根据命令查询,也就是后面带的:

--registry-mirror=https://aa25jngu.mirror.aliyuncs.com,就能知道阿里云镜像加速器配置完成了。

接下来运行 helloworld ,也就是 docker run hello-world,意思是以 docker 客服端命令的方式去运行一个叫 helloworld 的镜像,docker 客服端是和 docker 沟通的命令终端窗口。

1.输入以下代码:

[root@guigu 桌面]# docker run hello-world

然后运行,得以下代码:

Unable to find image ’hello-world: latest’ locally

如图:

image.png

在本地并不能找到镜像 hello-world 。运行的这个命令后跟着一个镜像 hello-world ,运行时首先是在本地寻找是否有镜像 hello-world(镜像和容器的关系:Docker 镜像就是一个只读的模板。镜像可以用来创建 Docker 容器,一个镜像可以创建很多容器。),也就是说,镜像 hello-world 只是一个类的模板,生成一个具体的 hello-world 容器实例。

可以看到,这里显示在本地没有找到这个 hello-world 镜像。找不到镜像 hello-world,如果需要运行 hello-world 就只能先生成容器。

也就是说,这里一共分为两步:

(1)在本地寻找 hello-world 镜像

(2)本地没有找到,就会从阿里云拉取这个镜像,拉取之后如图:

image.png

可以看到,这里有一个 sha256 的 hash 码:

455e23a9cf5a1a216bd8b0d71b08a25e4144c2ecf6adb26df9620245ba99529

2.然后是 Downloaded newer 的镜像对于 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 theexecutable 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.

这里显示的是,这个消息向用户展现,如果是安装界面,会显示 working correctly,也就是证明安装、运行和配置全部完成了。

如图:

image.png 

Docker run 在 Client 端也就是命令含终端窗口,就会去客户端访问 docker 安装,docker 主机,里面有一个 docker 的主线程, daemon 后台程序会继续命令 run 去 run 容器。

3.容器是如何生成的?

docker 上面有很多集装箱,到港口后需要卸载集装箱,这个时候在运作的就是这些集装箱。

但是这些集装箱是不存在的,因为容器需要镜像生成,没有 hello-world 容器就只能找 hello-world 镜像,如果镜像也没有,就需要在阿里云里面拉取镜像到本地。也就是说,由于本地没有 hello-world 镜像,所以会下载一个 hello-world 镜像,并在容器内运行。

请看以下代码:

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/

这段提示是测试的小脚本,输入这段提示之后,hello world 就会停止运行,容器自动终止。

4.run 的流程

如图:

image.png

流程是:

(1)首先在本机中寻找 hello world 镜像。

(2)如果本机有这个镜像,就以改镜像为模板生产容器实例运行。如果本机没有,就先去 Docker Hub(这里改为了阿里云 Hub) 查找 hello world 镜像。

(3)如果 Hub 内可以找到该镜像,就下载该镜像到本地,以该镜像为模板生产容器实例运行。如果不能找到,就会显示返回失败错误,查不到该镜像。

如图:

image.png

输入以下代码:

[rooteatquigu桌面]#docker run hello-worldoiuweoriuewr

然后会显示:

Unable to find image'

hello-worldoiuweoriuewr:latest'locally

Error response from daemon:Image does not exist

[rooteatguigu桌面]

可以看到,运行后发现本地没有这个镜像,然后去阿里云寻找,发现也没有这个镜像,以上就是 helloworld 的运行流程。

至此,已经完成了 Docker 的安装和 hello world 的运行。

相关文章
|
Docker 容器 开发工具
九步构建自己的hello world Docker镜像
Docker镜像构建是通过Dockerfile来构建的,里面运行的程序是可以自定的,从编写程序到安装Docker镜像,可以一气呵成。接下来我们就通过九步实现一个自定义的镜像的制作、构建及运行。
7691 0
|
Docker 容器
Docker服务启动失败报错:Job for docker.service failed because the control process exited with error code.
Docker服务启动失败报错:Job for docker.service failed because the control process exited with error code.
7838 1
|
Linux Docker 容器
Centos安装docker(linux安装docker)——超详细小白可操作手把手教程,包好用!!!
本篇博客重在讲解Centos安装docker,经博主多次在不同服务器上测试,极其的稳定,尤其是阿里的服务器,一路复制命令畅通无阻。
22146 5
Centos安装docker(linux安装docker)——超详细小白可操作手把手教程,包好用!!!
如何访问GitHub快的飞起?两步解决访问超时GitHub,无法访问GitHub的问题
这篇文章提供了几种方法来解决访问GitHub时速度慢或超时的问题,包括使用代理服务器、下载加速工具,以及考虑使用国内代码管理网站如码云(gitee)来加速下载GitHub上的资源。
如何访问GitHub快的飞起?两步解决访问超时GitHub,无法访问GitHub的问题
|
JavaScript
Vue3倒计时(Countdown)
这篇文章介绍了如何在Vue 3中创建一个可自定义的倒计时组件(Countdown),允许设置标题、前缀、后缀、格式和样式,并提供了组件的实现代码和使用示例。
1301 2
Vue3倒计时(Countdown)
阿里云镜像公共仓库使用
这篇文章介绍了如何使用阿里云镜像公共仓库,包括登录管理界面、创建命名空间、推送和拉取镜像的详细步骤。
9084 5
阿里云镜像公共仓库使用
|
Ubuntu Linux 网络安全
Docker&Docker Compose安装(离线+在线)
Docker&Docker Compose安装(离线+在线)
21365 1
|
云安全 人工智能 弹性计算
安装Docker 配置阿里云镜像加速
安装Docker,配置环境,配置阿里云镜像加速地址,查看镜像,卸载docker,卸载docker引擎,主机上的映像、容器、卷或自定义配置文件不会自动删除。要删除所有映像、容器和卷的方法
3237 0
安装Docker 配置阿里云镜像加速

热门文章

最新文章