Docker container monitoring and log management implementation process analysis

Docker container monitoring and log management implementation process analysis

When the scale of Docker deployment becomes larger, it is necessary to monitor the container. Generally, Docker comes with several monitoring subcommands such as ps, top, and stats. Then there is the popular open source monitoring tool Prometheus.

Docker's own monitoring subcommand ps

docker ps , lists containers, convenient for viewing currently running containers, the following is the command syntax and parameter syntax

docker ps [OPTIONS]

OPTIONS description:

  • -a : Display all containers, including those that are not running.
  • -f: Filter the displayed content according to the conditions.
  • --format : Specify the template file for the return value.
  • -l : Display recently created containers.
  • -n : List the n most recently created containers.
  • --no-trunc : Do not truncate output.
  • -q : Silent mode, only display the container number.
  • -s : Display the total file size.

Output details:

  • CONTAINER ID: Container ID.
  • IMAGE: The image to use.
  • COMMAND: The command to run when starting the container.
  • CREATED: The time when the container was created.
  • STATUS: Container status.

There are 7 states:

  • created
  • restarting
  • running
  • removing
  • paused
  • exited
  • dead

PORTS: The container's port information and the connection type used (tcp\udp).

NAMES: Automatically assigned container names.

The new version of Docker provides a new command docker container ls, which has the same function and usage as docker container ps. However, the meaning of ls may be more accurate than ps, so it is recommended.

top

If you want to know which processes are running in a container, you can execute the docker container top command as follows:

The command can also be followed by parameters of the Linux operating system ps command to display specific information, such as -au. The execution result of docker container top [container name] -au is as follows:

stats

Docker container stats is used to display the usage of various resources for each container.


By default, a real-time list is displayed, showing the CPU usage, memory, and available space of each container.

If the memory limit is not specified when the container is started, the stats command will display the total amount of host memory, but this does not mean that each container can use so much memory. In addition, the docker container stats command will also display the container network and disk IO data. You can specify the name of the container after the stats command to display data for certain containers.

Docker logs

Docker's logging feature is configured by default.

For a running container, Docker sends logs to the container's standard output device (STDOUT) and standard error device (STDERR). STDOUT and STDERR are actually the container's console terminal.

If you want to view the container logs, there are two ways:

Attach to this container.

Use the docker logs command to view the logs.

The ttach method is not very convenient in practice because:

Only logs after attach can be seen, and logs before that are not visible.

Exiting the attach state is more troublesome (Ctrl+p then Ctrl+q key combination), and it is easy to kill the container accidentally (for example, by pressing Ctrl+C).

The recommended way to view container logs is to use the docker logs command.

As shown below:

docker logs can print the complete logs since the container was started, and the -f parameter can continue to print the newly generated logs, which is the same as tail -f in linux.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Golang implements heartbeat monitoring function for docker container
  • Implement dynamic management and monitoring of docker containers based on spring-boot and docker-java [with complete source code download]
  • Zabbix monitors docker container status [recommended]
  • Detailed explanation of the construction of Docker container visual monitoring center
  • Use Grafana to display monitoring charts of Docker containers and set email alert rules (illustration)
  • Docker container memory monitoring principle and application
  • Python script to monitor docker container

<<:  Vue implements a small countdown function

>>:  How to remotely log in to the MySql database?

Recommend

Vue routing relative path jump method

Table of contents Vue routing relative path jump ...

Details of the order in which MySQL reads my.cnf

Table of contents The order in which MySQL reads ...

Detailed installation steps for MySQL 8.0.11

This article shares the installation steps of MyS...

How to install MySQL database on Debian 9 system

Preface Seeing the title, everyone should be thin...

MySQL 5.7.20 zip installation tutorial

MySQL 5.7.20 zip installation, the specific conte...

HTML table tag tutorial (35): cross-column attribute COLSPAN

In a complex table structure, some cells span mul...

Detailed explanation of JavaScript error capture

Table of contents 1. Basic usage and logic 2. Fea...

MySQL 8.0.20 installation and configuration method graphic tutorial

MySQL download and installation (version 8.0.20) ...

How to install Apache service in Linux operating system

Download link: Operating Environment CentOS 7.6 i...

Usage and demonstration of ref in Vue

ref definition: used to register reference inform...

A brief discussion on the pitfalls of react useEffect closure

Problem code Look at a closure problem code cause...

Vue opens a new window and implements a graphic example of parameter transfer

The function I want to achieve is to open a new w...

Website Design Experience Summary of Common Mistakes in Website Construction

Reminder: Whether it is planning, designing, or de...

A brief discussion of several browser compatibility issues encountered

background Solving browser compatibility issues i...

JavaScript design pattern chain of responsibility pattern

Table of contents Overview Code Implementation Pa...