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

A brief discussion on the magical uses of CSS pseudo-elements and pseudo-classes

CSS plays a very important role in a web page. Wi...

Detailed explanation of DOM style setting in four react components

1. Inline styles To add inline styles to the virt...

Unicode signature BOM (Byte Order Mark) issue for UTF-8 files

I recently encountered a strange thing when debug...

Detailed explanation of CSS float property

1. What is floating? Floating, as the name sugges...

Let's talk about bitwise operations in React source code in detail

Table of contents Preface Several common bit oper...

Analyze MySQL replication and tuning principles and methods

1. Introduction MySQL comes with a replication so...

HTML unordered list bullet points using images CSS writing

Create an HTML page with an unordered list of at l...

The use of MySQL triggers and what to pay attention to

Table of contents About Triggers Use of triggers ...

Share some key interview questions about MySQL index

Preface An index is a data structure that sorts o...

JavaScript article will show you how to play with web forms

1. Introduction Earlier we introduced the rapid d...

Seven Principles of a Skilled Designer (1): Font Design

Well, you may be a design guru, or maybe that'...

How to implement second-level scheduled tasks with Linux Crontab Shell script

1. Write Shell script crontab.sh #!/bin/bash step...

Two ways to clear float in HTML

1. Clear floating method 1 Set the height of the ...

Summary of Docker configuration container location and tips

Tips for using Docker 1. Clean up all stopped doc...