Tomxin7

Simple, Interesting | 简单,有趣

第一个Docker镜像?

尝试运行docker自带的镜像“hello-world”,了解docker镜像的下载和启动。
docker的整个生命周期有三部分组成:镜像(image)+容器(container)+仓库(repository)

1、查看当前镜像

[root@tomxin docker]# docker images
结果应该是当前系统暂时还没有任何镜像

2、下载“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

3、再次查看镜像

[root@tomxin docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/hello-world latest 4ab4c602aa5e 5 weeks ago 1.84 kB

第一个docker容器

运行“hello-world”容器

镜像和容器的区别:容器是由镜像实例化而来,这和我们学习的面向对象的概念十分相似,我们可以把镜像看作类,把容器看作类实例化后的对象。

1、查看容器

[root@tomxin docker] docker ps -a
应该暂时还没有容器

2、运行“hello-world”,运行成功后,docker会创建一个容器,上面输出了hello-world这个项目运行,docker所做的工作步骤

[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/

3、查看全部容器,可以看到在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基本的工作原理。

最新文章

  1. 【干货】解密监控宝Docker监控实现原理
  2. js从外部获取图片
  3. Runnable,Thread实现多线程以及Runnable的同步资源共享
  4. 记、基于react-router的单页应用
  5. MySQL5.6 on Windows 安装失败: String was not recognized as a valid DateTime
  6. json.parse 与 json.stringfy
  7. Elasticsearch 配置
  8. 银行IT入门深似海
  9. 推荐开源Api文档生成工具——Doxygen
  10. SQL性能优化之一
  11. struct可以拥有class般的构造函数
  12. Django-1- urls的路由配置, 命名, 重定向, path及re_path
  13. [MySQL] 联合索引与using index condition
  14. 【Python 24】52周存钱挑战4.0(函数)
  15. 聊聊Google DSM产品的发布
  16. 为什么matlab激活完后还要激活(Matlab2012b license失效解决办法)
  17. 解决Hive与Elasticsearch共有库 guava 冲突 NoSuchMethodError
  18. as3 TweenMax TweenLite方法
  19. 《Windows核心编程》第3章——handle复制相关实验
  20. ntpdate设置

热门文章

  1. gitlab访问慢,出现502,特别卡,耗内存cpu解决办法
  2. Mybatis 学习一
  3. Wordpress自动更新失败
  4. CodeForces - 755B PolandBall and Game(博弈)
  5. jsp与spring mvc后台controller间参数传递处理之总结
  6. 获取指定进程号,并kill掉
  7. Oracle 序列(查询序列的值,修改序列的值)
  8. MySQL过程和游标
  9. Spark 内存管理
  10. K8S Kubernetes 简单介绍 转自 http://time-track.cn/kubernetes-trial.html Kubernetes初体验