Hello Docker

前一篇简单介绍了docker的组织架构,这一篇让我们简单run起一个docker应用hello-world

  • 运行环境
➜  ~ docker -v
Docker version 18.03.1-ce, build 9ee9f40
  • 运行docker run hello-world
➜  ~ docker run hello-world
Unable to find image 'hello-world:latest' locally // 首先去找本地是否有hello-world的镜像
latest: Pulling from library/hello-world // 如果没有指定tag版本会去下载镜像的latest版本
9bb5a5d4561a: Pull complete
Digest: sha256:f5233545e43561214ca4891fd1157e1c3c563316ed8e237750d59bde73361e77
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/engine/userguide/

我们可以看到Docker给我们打招呼Hello from Docker!
告诉我们生成这个消息,Docker做了以下几个步骤

  1. Docker 客户端连接到Docker的守护进程
  2. Docker 服务端从市场上下载hello-world的镜像
  3. Docker守护进程从该映像创建了一个新的容器,该容器运行可执行文件,生成当前正在阅读的输出。
  4. Docker守护进程将流式输出传输到Docker客户端,并将其发送到终端。
  • 然后我们看看现在的docker image和container的情况
➜  ~ docker image ls // 查看镜像列表
REPOSITORY                                    TAG                 IMAGE ID            CREATED             SIZE
hello-world                                   latest              e38bc07ac18e        3 weeks ago         1.85kB
➜  ~ docker ps // 查看正在运行的容器列表
CONTAINER ID        IMAGE                                         COMMAND                  CREATED             STATUS              PORTS                    NAMES
➜  ~ docker ps -a // 查看所有的容器列表
CONTAINER ID        IMAGE                                         COMMAND                  CREATED                  STATUS                      PORTS                    NAMES
c21c024a9766        hello-world                                   "/hello"                 Less than a second ago   Exited (0) 4 seconds ago                             eager_kowalevski
  • 那么我们如何删除一个容器、一个镜像呢?
➜  ~ docker rmi e38bc07ac18e // 当镜像被用作容器创建时,不能删除
Error response from daemon: conflict: unable to delete e38bc07ac18e (must be forced) - image is being used by stopped container c21c024a9766
➜  ~ docker rm c21c024a9766 // 删除容器
c21c024a9766
➜  ~ docker ps -a // 查看容器列表、删除成功
CONTAINER ID        IMAGE                                         COMMAND                  CREATED             STATUS                      PORTS                    NAMES
➜  ~ docker rmi e38bc07ac18e // 删除镜像
Untagged: hello-world:latest
Untagged: hello-world@sha256:f5233545e43561214ca4891fd1157e1c3c563316ed8e237750d59bde73361e77
Deleted: sha256:e38bc07ac18ee64e6d59cf2eafcdddf9cec2364dfe129fe0af75f1b0194e0c96
Deleted: sha256:2b8cbd0846c5aeaa7265323e7cf085779eaf244ccbdd982c4931aef9be0d2faf
➜  ~ docker image ls // 查看镜像列表、删除成功
REPOSITORY                                    TAG                 IMAGE ID            CREATED             SIZE
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Docker: Build, Ship, and Run Any App, Anywhere在任何地方构建、交付和...
    圣杰阅读 6,970评论 0 10
  • 《Docker从入门到实践》阅读笔记 原书地址: https://yeasy.gitbooks.io/docker...
    GuoYuebo阅读 13,928评论 1 39
  • 前言 对于二叉树来说,层次遍历可以说是很平常的,但由于其应用广泛,比如可以用来求二叉树的高度和宽度,因而非常重要。...
    林天涯阅读 4,879评论 0 1
  • 常听人说,这个社会是个多元的时代,价值取向多元化、文化取向多元化、甚至于性取向也多元化。多元被炒作成为一个很...
    新功利主义阅读 1,639评论 0 1
  • IP电影,你能把观众当傻瓜,观众就能让你对票房傻眼。——列车长 霸气的人生何须解释?每个天才都是随便开挂的角儿!在...
    公元2046阅读 2,929评论 0 0

友情链接更多精彩内容