Docker入门实践(三) 基本操作

本文介绍了Docker的基本操作,包括创建、查看、拉取和管理容器及镜像。通过实例展示了如何运行hello-world容器,查看本地镜像,搜索Docker Hub上的镜像,拉取并运行Tomcat容器,以及管理容器日志、停止、启动、删除容器和镜像。此外,还提及了数据卷的初步使用。
摘要由CSDN通过智能技术生成

本文已迁移到我的新博客地址,欢迎访问:

blog.favorstack.io


Docker安装完毕,我们就可以试着来运行一些命令了,看看docker可以干什么。

(一) 创建一个容器

首先,让我们运行一个最简单的容器,hello-world。如果安装没有问题,并运行正确的话,应该会出现下面的结果:

$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c04b14da8d14: Pull complete
Digest: sha256:0256e8a36e2070f7bf2d0b0763dbabdd67798512411de4cdcf9431a1feb60fd9
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.
 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 Hub account:
 https://hub.docker.com

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

可以看到,上述结果给了我们很多信息,首先,打印出了一条信息:Hello from Docker!
接着简单描述了一下产生该条信息所经历的一系列步骤:

1 Docker客户端连接到守护进程
2 Docker守护进程从Docker Hub拉取了hello-world镜像
3 Docker守护进程从该镜像创建了一个容器,来执行了命令并输出了我们当前看的这条消息
4 Docker守护进程将容器中的标准输出转发到你的终端。

需要补充一点的是,docker在运行一个容器时,首先会检查本地是否存在指定的镜像,如果有,则直接运行,如果没有,才会去Docker Hub上拉取。这也就是命令结果第一行为什么会显示Unable to find image 'hello-world:latest' locally的原因。

接下来,我们可以看一下目前所有的容器:

$ docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                     PORTS                    NAMES
1a058b3cde45        hello-world         "/hello"                 3 m
  • 3
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值