Hello|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:latestHello 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 bashShare 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/

【Hello|Hello Docker】我们可以看到Docker给我们打招呼Hello from Docker!
告诉我们生成这个消息,Docker做了以下几个步骤
  1. Docker 客户端连接到Docker的守护进程
  2. Docker 服务端从市场上下载hello-world的镜像
  3. Docker守护进程从该映像创建了一个新的容器,该容器运行可执行文件,生成当前正在阅读的输出。
  4. Docker守护进程将流式输出传输到Docker客户端,并将其发送到终端。
  • 然后我们看看现在的docker image和container的情况
?~ docker image ls // 查看镜像列表 REPOSITORYTAGIMAGE IDCREATEDSIZE hello-worldlateste38bc07ac18e3 weeks ago1.85kB ?~ docker ps // 查看正在运行的容器列表 CONTAINER IDIMAGECOMMANDCREATEDSTATUSPORTSNAMES ?~ docker ps -a // 查看所有的容器列表 CONTAINER IDIMAGECOMMANDCREATEDSTATUSPORTSNAMES c21c024a9766hello-world"/hello"Less than a second agoExited (0) 4 seconds agoeager_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 IDIMAGECOMMANDCREATEDSTATUSPORTSNAMES ?~ docker rmi e38bc07ac18e // 删除镜像 Untagged: hello-world:latest Untagged: hello-world@sha256:f5233545e43561214ca4891fd1157e1c3c563316ed8e237750d59bde73361e77 Deleted: sha256:e38bc07ac18ee64e6d59cf2eafcdddf9cec2364dfe129fe0af75f1b0194e0c96 Deleted: sha256:2b8cbd0846c5aeaa7265323e7cf085779eaf244ccbdd982c4931aef9be0d2faf ?~ docker image ls // 查看镜像列表、删除成功 REPOSITORYTAGIMAGE IDCREATEDSIZE

    推荐阅读