Docker Hello-World镜像运行测试
一、命令:docker run hello-world
命令解释:以docker客户端命令的方式运行hello-world镜像
命令运行结果:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | hadoop @Docker :/opt/docker$ docker run hello-world <strong>Unable to find image 'hello-world:latest' locally</strong> latest: Pulling from library/hello-world d1725b59e92d: Pull complete Digest: sha256:0add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9fde470971e499788 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: |
通过分析命令运行结果,说明docker内部的工作原理:
(1)加载本地镜像
1 2 | # 首先在本地查找 'hello-world:latest' 镜像 Unable to find image 'hello-world:latest' locally |
docker run一个镜像,那么则会以这个镜像作为类的模板生成一个hello-world容器实例,一个具体的对象。注意:该命令首先会查找本地的hello-world镜像。
(2)从阿里云服务器上拉去hello-world镜像
latest: Pulling from library/hello-world d1725b59e92d: Pull complete Digest: sha256:0add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9fde470971e499788 Status: Downloaded newer image for hello-world:latest
(3)、运行
1 2 | Hello from Docker! This message shows that your installation appears to be working correctly. |
(4)运行原理分析
首先,我们在docker客户端(命令行终端窗口),执行docker命令;
客户端回去访问我们docker所在的那台服务器主机,实质而言主机上有一个Docker daemon主线程,它会监听到客户端的docker命令,它会run容器(Container),而容器又是通过镜像生成的。如果没有hello-world容器,它就会在本地查找hello-world镜像,如果本地找到了就会直接生成一个hello-world容器,否则,会向阿里云服务器仓库拉去相应的镜像;
从阿里云服务器仓库上拉取hello-world镜像到本地,再生成容器,进而运行。
(5)docker容器终止运行
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 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/ |
输出这段提示以后,hello world就会停止运行,容器自动终止
二、run到底做了什么呢?
docker run hello-world命令运行原理图:
分类:
docker
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!