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

作者:神秘网友 发布时间:2020-10-15 21:45:01

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

如何获取有关在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
如何获取有关在Docker中运行容器和映像的信息?
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
如何获取有关在Docker中运行容器和映像的信息?
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
如何获取有关在Docker中运行容器和映像的信息?
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
如何获取有关在Docker中运行容器和映像的信息?
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
如何获取有关在Docker中运行容器和映像的信息?
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
如何获取有关在Docker中运行容器和映像的信息?
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/

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

  1. 如何使用unet网络进行训练和预测

    如何使用unet网络进行训练和预测 环境配置 git clone https://github.com/zhixuhao/unet.gitD:cd D:\KerasProject\unetconda create -n unet python=3.6activate unet conda install tensorflow-gpu==1.12conda install keraspip install jupyterpip install

  2. 如何使用Fsutil在Windows中检查和修复文件系统?

    如何使用Fsutil在Windows中检查和修复文件系统? Windows provides command line tool named fsutils to manage disk related issues. This tool provides management capabilities volume information to repairing file system, setting quotas to listing

  3. 如何安装IntelliJ IDEA 最新版本——详细安装使用 IDEA 创建 hel

    如何安装IntelliJ IDEA 最新版本——详细安装使用 IDEA 创建 hello world 程序 IntelliJ IDEA 简称 IDEA,被业界公认为最好的 Java 集成开发工具,尤其在智能代码助手、代码自动提示、代码重构、代码版本管理(Git、SVN、Maven)、单元测试、代码分析等方面有着

  4. 使用Windows Powershell从命令行获取服务服务管理

    使用Windows Powershell从命令行获取服务服务管理 Windows Powershell provides easy to use commands or command-lets to manage Windows systems. Powershell can be used to manage Windows Services and provides builtin command for related operations

  5. 如何以Windows的不同方式从命令行启动应用程序?

    如何以Windows的不同方式从命令行启动应用程序? Windows is very user friendly and GUI oriented operating system. Other operating systems like Unix, Linux, BSD came from non-GUI heritance and adopted the GUI experience in recent decade very go

  6. 如何使用Dir在Windows命令行中导航,列出文件和目录?

    如何使用Dir在Windows命令行中导航,列出文件和目录? Windows operating system provides command line tool named MS-DOS. This command line have different tools and capabilities for daily operations. We will look some simple steps about usage li

  7. 如何在Windows中使用Schtasks从命令行计划任务?

    如何在Windows中使用Schtasks从命令行计划任务? Recurring tasks are generally schedules with scheduled task manager. Scheduled task manager have GUI for management but creating a task in 20 different servers is very hard and trivial job. Wind

  8. 如何在Windows中使用Xcopy复制文件和备份?

    如何在Windows中使用Xcopy复制文件和备份? Windows provides very featureful command which is used to copy files can take backups named xcopy . Xcopy can be used copy files from one partition to other partition or a usb drive. Xcopy also suppo