Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure the log driver

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the relevant knowledge of "how to configure the log driver". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Log driver (Logging Driver)

In Docker, application logs are stored in a variety of ways, which are called log drivers (Logging Driver).

It has many types of log drivers, such as none, local, json-file, etc., and it can also implement its own log driver. For details, please refer to the official "Supported logging drivers" and "Use a logging driver plugin" documents.

Matters needing attention

The content of this note is the study and arrangement of the official 19.03/Configure logging drivers documents. Please refer to the official documents for details.

Configure the default log driver

The default is json-file log driver, but it can be modified.

Configure the global log driver

Modify the / etc/docker/daemon.json configuration file (example):

{"log-driver": "syslog", "log-opts": {"max-size": "500m", "max-file": "3", "labels": "production_status", "env": "os,customer"}}

The properties available for log-opts depend on the log driver type (log-driver) and can be added if the log driver supports other options.

Configure the container log driver

You can also configure log drivers for specific containers. When starting the container, specify the-- log-driver option:

Docker run-it-- log-driver none alpine ash configuration log distribution model

Log distribution consists of two models: (1) blocking and (2) non-blocking.

"non-blocking" is used to prevent the application from crashing due to pressure at the back end of the log. For details, please refer to the official documentation.

Use the log label

Log labels can be specified using the-e or-- label options, and some tags are appended to the generated logs. For details, please refer to the official documentation.

Log-driven limit

The enterprise version supports "dual logging", that is, no matter which log driver you use, you can use the docker logs command to view it, but currently, the community version (01max 08DB 2020) only supports viewing local, json-file and journald log drivers, so "we" usually only need to pay attention to these three.

Reading the rotation log requires consumption of disk and CPU usage

The maximum log file size is determined by the Docker data directory size

Where are the logs for the default log driver, configuration, and problem service processes (Dokcer) that require our attention?

If you run the Docker service using systemd, the logs are managed by systemd-journald. Use journalctl-u docker.service to view the Docker log.

What is the default log driver?

The default log driver is different for different versions of Docker. According to the official document 19.03/Configure the default logging driver: The default logging driver is json-file.

Execute the command docker info-- format "{{.LoggingDriver}}" to view the current default log driver.

Execute the command docker inspect-f'{{.HostConfig.LogConfig.Type}'to view the log driver of the container.

Where is the log of the container kept?

/ var/lib/docker/containers//-json.log

Does the container's log rotate automatically and free up space?

If the container uses json-file log driver, according to the description of max-size in the official 19.03/JSON File logging driver document, the log of the container will not be changed and will continue to grow.

Through the test at Docker 18.09.1, the log file-json.log will continue to grow, so we need to adjust the log driver parameters.

This is the end of "how to configure log drivers". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report