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 的运行。

相关文章
|
2天前
|
Java 网络安全 开发者
【Docker】5、Dockerfile 自定义镜像(镜像结构、Dockerfile 语法、把 Java 项目弄成镜像)
【Docker】5、Dockerfile 自定义镜像(镜像结构、Dockerfile 语法、把 Java 项目弄成镜像)
50 0
|
2天前
|
存储 人工智能 API
minio 使用docker安装和入门案例demo
minio 使用docker安装和入门案例demo
|
9月前
|
Linux Go Docker
goland如何把go项目打包进docker镜像
goland如何把go项目打包进docker镜像
330 0
|
10月前
|
Docker 容器
`target/demo.jar` 文件添加到 Docker 镜像
`target/demo.jar` 文件添加到 Docker 镜像
82 1
|
10月前
|
JavaScript 前端开发 Python
|
Linux Shell 开发工具
DockerFile介绍、编写dockerfile、构建(build)、运行(run)、实例
>DockerFile是用来构建Docker镜像的构建文件,是由一系列命令参数构成的脚本。 #### 二、DockerFile的一些规则 * 每条保留字指令都必须为大写字母且后面要跟随至少一个参数 * 指令顺序执行,遵循从上到下原则 * #表示注释 * 每条指令都会创建一个新的镜像层,并对镜像进行提交
282 0
DockerFile介绍、编写dockerfile、构建(build)、运行(run)、实例
|
Ubuntu Shell Linux
docker基本使用加载和输出
docker基本使用加载和输出
114 0
docker基本使用加载和输出
|
开发者 Docker 容器
hello world 镜像|学习笔记
快速学习 hello world 镜像
308 0
hello world 镜像|学习笔记
|
Java Linux Shell
Docker file 案例-自定义镜像 mycentos | 学习笔记
快速学习 Docker file 案例-自定义镜像 mycentos
149 0
Docker file  案例-自定义镜像 mycentos | 学习笔记
|
Java Linux Shell
DockerFile 案例-自定义镜像 mycentos|学习笔记
快速学习 DockerFile 案例-自定义镜像 mycentos
144 0
DockerFile 案例-自定义镜像 mycentos|学习笔记