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

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 createdCREATED
列显示创建容器多少时间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

This command will list following information about the container images.
此命令将列出有关容器映像的以下信息。
REPOSITORY
column shows the name and repository of the imageREPOSITORY
列显示图像的名称和存储库TAG
columns shows related tags which is generally provides version information about the container imageTAG
列显示相关标签,通常提供有关容器映像的版本信息IMAGE ID
column shows image unique identifierIMAGE ID
列显示图像唯一标识符CREATED
columns shows the creation time of the imageCREATED
列显示图像的创建时间SZIE
column shows the size of the imageSZIE
列显示图像的大小
显示容器日志(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

As we can see there are enormous information. We will look some of the important of them below.
如我们所见,这里有很多信息。 我们将在下面介绍其中的一些重要内容。
ID
column shows the container idID
列显示容器IDState
line shows current state of the containerState
行显示容器的当前状态Mounts
line shows mounted sharesMounts
线显示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

显示网络和端口信息(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 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

Here are following information;
以下是以下信息;
CONTAINER
column shows container idCONTAINER
列显示容器IDCPU
column shows the current CPU usageCPU
列显示当前的CPU使用率MEMUSAGE
column show memory usageMEMUSAGE
列显示内存使用情况MEM %
column shows the usage in percentage formatMEM %
列以百分比格式显示使用情况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
列显示进程总数。
翻译自: https://www.poftut.com/get-information-running-containers-images-docker/
如何获取有关在Docker中运行容器和映像的信息?相关教程
-
如何使用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
-
如何使用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
-
如何安装IntelliJ IDEA 最新版本——详细安装使用 IDEA 创建 hel
如何安装IntelliJ IDEA 最新版本——详细安装使用 IDEA 创建 hello world 程序 IntelliJ IDEA 简称 IDEA,被业界公认为最好的 Java 集成开发工具,尤其在智能代码助手、代码自动提示、代码重构、代码版本管理(Git、SVN、Maven)、单元测试、代码分析等方面有着
-
使用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
-
如何以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
-
如何使用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
-
如何在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
-
如何在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