如何获取有关在Docker中运行容器和映像的信息?

Docker provides different tools to monitor the containers. In a busy environment there will be a lot of images and containers hard to remember. We can use information sub-commands provided by docker to get more detailed port, disk, diff, event stat information. While running docker sub-commands we need root privileges.

Docker提供了不同的工具来监视容器。 在繁忙的环境中,会有很多图像和容器难以记住。 我们可以使用docker提供的information子命令来获取更详细的端口,磁盘,差异,事件统计信息。 在运行docker子命令时,我们需要root特权。

列出正在运行的容器 (List Running Containers)

In a busy environment there will be a lot of containers. Listing running containers are important part of the container management. We can list running containers with ps subcommand.

在繁忙的环境中,会有很多容器。 列出正在运行的容器是容器管理的重要组成部分。 我们可以使用ps子命令列出正在运行的容器。

$ docker ps
List Running Containers
List Running Containers
列出正在运行的容器

As we can see ps command provides following information about each running container

如我们所见,ps命令提供了有关每个正在运行的容器的以下信息

  • CONTAINER ID column shows uniq ID of the container. This is is used for the most of the container operations like stop, clone, connect etc.

    CONTAINER ID列显示容器的唯一ID。 这用于大多数容器操作,如停止,克隆,连接等。

  • IMAGE column show the base image used to create related container.

    IMAGE列显示用于创建相关容器的基本图像。

  • COMMAND column shows the command running in the container while starting.

    COMMAND列显示启动时在容器中运行的命令。

  • CREATED column shows how much time ago the container is created

    CREATED列显示创建容器多少时间

  • STATUS columns shows the uptime of the container.

    STATUS列显示容器的正常运行时间。

  • PORTS columns shows the redirected ports and related network configuration.

    PORTS列显示重定向的端口和相关的网络配置。

  • NAME column shows the human readable name of the container. If it is not given explicitly docker engine assign random name.

    NAME列显示容器的可读名称。 如果未明确给出,则docker引擎分配随机名称。

列出图片 (List Images)

As we know docker containers are created from previously pulled and stored images. Images contains file system of the containers. We can list locally avaible images with the -image sub command.

众所周知,docker容器是根据先前提取和存储的图像创建的。 图像包含容器的文件系统。 我们可以使用-image子命令列出本地可用的图像。

$ docker images
List Images
List Images
列出图片

This command will list following information about the container images.

此命令将列出有关容器映像的以下信息。

  • REPOSITORY column shows the name and repository of the image

    REPOSITORY列显示图像的名称和存储库

  • TAG columns shows related tags which is generally provides version information about the container image

    TAG列显示相关标签,通常提供有关容器映像的版本信息

  • IMAGE ID column shows image unique identifier

    IMAGE ID列显示图像唯一标识符

  • CREATED columns shows the creation time of the image

    CREATED列显示图像的创建时间

  • SZIE column shows the size of the image

    SZIE列显示图像的大小

LEARN MORE  Linux ss Command Tutorial With Examples
了解更多Linux的命令教程和示例

显示容器日志(Show Containers Logs)

Container will create docker engine related logs while running and operations. These log can be seen without searching them in directories with simple logs command. We will also provide the container id to specify container we want to see logs. In this example the container id is feb2c71e09e8

容器将在运行和操作时创建与Docker引擎相关的日志。 无需使用简单logs命令在目录中搜索即可查看这些日志。 我们还将提供容器ID,以指定我们要查看日志的容器。 在此示例中,容器ID为feb2c71e09e8

$ docker logs feb2c71e09e8

获取有关运行容器的详细信息 (Get Detailed Information About Running Container)

One of the best feature of docker engine is that it can provide a lot of information about the running containers. these information is provided in JSON format. We will use inspect subocmmand to list all details about the container.

泊坞窗引擎的最佳功能之一是,它可以提供有关正在运行的容器的大量信息。 这些信息以JSON格式提供。 我们将使用inspect subocmmand列出有关容器的所有详细信息。

$ docker inspect feb2c71e09e8
Get Detailed Information About Running Container
Get Detailed Information About Running Container
获取有关运行容器的详细信息

As we can see there are enormous information. We will look some of the important of them below.

如我们所见,这里有很多信息。 我们将在下面介绍其中的一些重要内容。

  • ID column shows the container id

    ID列显示容器ID

  • State line shows current state of the container

    State行显示容器的当前状态

  • Mounts line shows mounted shares

    Mounts线显示Mounts份额

  • NetworkSettings line shows detailed information like IP address, default gateway etc.

    NetworkSettings行显示详细信息,例如IP地址,默认网关等。

显示的容器事件 (Shown Container Events)

Containers have different events during the work. These events can be viewed with events sub-command.  This command will start an real  time console and print all events in real time like start, die, attach, resize events.

容器在工作期间会有不同的事件。 可以使用events子命令查看这些事件。 此命令将启动一个实时控制台,并实时打印所有事件,例如开始,死亡,附加,调整大小。

$ docker events
Shown Container Events
Shown Container Events
显示的容器事件

显示网络和端口信息(Show Network And Port Information)

Network is important aspect for the containers. By default newly created containers will connect to the external networks and internet with a NAT. But docker engine also supports port mapping and IP address nat. We can list these existing NATS and port mapping with port command. We will also provide the container ID.

网络是容器的重要方面。 默认情况下,新创建的容器将使用NAT连接到外部网络和Internet。 但是docker引擎还支持端口映射和IP地址nat。 我们可以使用port命令列出这些现有的NATS和端口映射。 我们还将提供容器ID。

$ docker port feb2c71e09e8

显示容器CPU使用率 (Show Container CPU Usage)

As we know containers are not virtual machines. They are just processes running on the host with restricted status. So They get CPU time from the host system. We can list given containers CPU usage with top command. We will also provide the containers ID.

众所周知,容器不是虚拟机。 它们只是在主机上运行的具有受限状态的进程。 因此,他们从主机系统获取CPU时间。 我们可以使用top命令列出给定容器的CPU使用率。 我们还将提供容器ID。

$ docker top a264a020b160
Show Container CPU Usage
Show Container CPU Usage
显示容器CPU使用率

显示容器资源使用情况(Show Container Resource Usage)

If we need real time stats about the running containers we can use stats command. This will give top like output in a simple way.

如果我们需要有关正在运行的容器的实时统计信息,可以使用stats命令。 这将以简单的方式提供类似top的输出。

$ docker stats
Show Container Resource Usage
Show Container Resource Usage
显示容器资源使用情况

Here are following information;

以下是以下信息;

  • CONTAINER column shows container id

    CONTAINER列显示容器ID

  • CPU column shows the current CPU usage

    CPU列显示当前的CPU使用率

  • MEMUSAGE column show memory usage

    MEMUSAGE列显示内存使用情况

  • MEM % column shows the usage in percentage format

    MEM %列以百分比格式显示使用情况

  • NET I/O column shows network I/O information.

    NET I/O列显示网络I / O信息。

  • BLOCK I/O column shows disk I/O information.

    BLOCK I/O列显示磁盘I / O信息。

  • PIDS column shows total number of processes.

    PIDS列显示进程总数。

LEARN MORE  Introduction To Scapy Network Packet Generator
了解更多Scapy网络数据包生成器简介

翻译自: https://www.poftut.com/get-information-running-containers-images-docker/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值