Docker log sharing
来源:互联网 发布:软件安装包备份 编辑:程序博客网 时间:2024/06/08 05:18
- View logs for a container or service
- Configure logging drivers
- Configure the default logging driver
- Configure the logging driver for a container
- Use a logging driver plugin
- Configure a container to use the plugin as the logging driver
- Install the logging driver plugin
- Log tags for logging driver
- available log driver
View logs for a container or service
- the docker service logs command shows information logged by all containers participating in a service. The information that is logged and the format of the log depends almost entirely on the container’s endpoint command.( this is for docker swarm)
- [By default], docker logs or docker service logs shows the command’s output just as it would appear if you ran the command interactively in a terminal. UNIX and Linux commands typically open three I/O streams when they run, called STDIN, STDOUT, and STDERR. STDIN is the commmand’s input stream, which may include input from the keyboard or input from another command. STDOUT is usually a command’s normal output, and STDERR is typically used to output error messages. By default, docker logs shows the command’s STDOUT and STDERR.
Configure logging drivers
Each Docker daemon has a default logging driver, which each container uses unless you configure it to use a different logging driver.
Configure the default logging driver
To configure the Docker daemon to default to a specific logging driver, set the value of log-driver to the name of the logging driver in the daemon.json file, which is located in /etc/docker/ on Linux hosts.
The default logging driver is json-file. The following example explicitly sets the default logging driver to syslog:
{ "log-driver": "syslog"}
If the logging driver has configurable options, you can set them in the daemon.json file as a JSON array with the key log-opts. The following example sets two configurable options on the json-file logging driver:
{ "log-driver": "json-file", "log-opts": { "labels": "production_status", "env": "os,customer" }}
Configure the logging driver for a container
When you start a container, you can configure it to use a different logging driver than the Docker daemon’s default, using the –log-driver** flag. If the logging driver has configurable options, you can set them using one or more instances of the –log-opt = flag. Even if the container uses the default logging driver, it can use different configurable options.**
The following example starts an Alpine container with the none logging driver.
$ docker run -it --log-driver none alpine ash
To find the current logging driver for a running container, if the daemon is using the json-file logging driver, run the following docker inspect command, substituting the container name or ID for < container>:
$ docker inspect -f '{{.HostConfig.LogConfig.Type}}' <CONTAINER>json-file
Use a logging driver plugin
Docker logging plugins allow you to extend and customize Docker’s logging capabilities beyond those of the built-in logging drivers. A logging service provider can implement their own plugins and make them available on Docker Hub, Docker Store, or a private registry. This topic shows how a user of that logging service can configure Docker to use the plugin.
Configure a container to use the plugin as the logging driver
After the plugin is installed, you can configure a container to use the plugin as its logging driver by specifying the –log-driver flag to docker run, as detailed in the logging overview. If the logging driver supports additional options, you can specify them using one or more –log-opt flags with the option name as the key and the option value as the value.
Install the logging driver plugin
To install a logging driver plugin, use docker plugin install < org/image>, using the information provided by the plugin developer.
You can list all installed plugins using docker plugin ls, and you can inspect a specific plugin using docker inspect.
Log tags for logging driver
The tag log option specifies how to format a tag that identifies the container’s log messages. By default, the system uses the first 12 characters of the container ID. To override this behavior, specify a tag option:
$ docker run --log-driver=fluentd --log-opt fluentd-address=myhost.local:24224 --log-opt tag="mailer"
Docker supports some special template markup you can use when specifying a tag’s value:
For example, specifying a –log-opt tag=”{{.ImageName}}/{{.Name}}/{{.ID}}” value yields syslog log lines like:
Aug 7 18:33:19 HOSTNAME hello-world/foobar/5790672ab6a0[9103]: Hello from Docker.
At startup time, the system sets the container_name field and {{.Name}} in the tags. If you use docker rename to rename a container, the new name is not reflected in the log messages. Instead, these messages continue to use the original container name.
available log driver
C:\Users\mcong\Desktop\github\docker-ce\components\engine\daemon\logdrivers_linux.go
import ( // Importing packages here only to make sure their init gets called and // therefore they register themselves to the logdriver factory. _ "github.com/docker/docker/daemon/logger/awslogs" _ "github.com/docker/docker/daemon/logger/fluentd" _ "github.com/docker/docker/daemon/logger/gcplogs" _ "github.com/docker/docker/daemon/logger/gelf" _ "github.com/docker/docker/daemon/logger/journald" _ "github.com/docker/docker/daemon/logger/jsonfilelog" _ "github.com/docker/docker/daemon/logger/logentries" _ "github.com/docker/docker/daemon/logger/splunk" _ "github.com/docker/docker/daemon/logger/syslog")
- Docker log sharing
- docker sharing -- code
- docker log driver
- Docker log driver plugin
- sharing
- Sharing
- Sharing
- Sharing
- Centos7下docker安装log.io日志监控
- runtime sharing
- Internal sharing
- Sharing Resources
- Sharing chocolate
- 1032:Sharing
- PAT_1032: Sharing
- false sharing
- Sharing Files
- 1032. Sharing
- 实验5 结合二叉树的二叉排序树设计
- 华为路由器接口编号与接口的对应关系
- opengles 管线
- js换行问题
- 关于修改页面带下拉框的选中问题
- Docker log sharing
- log4j日志的配置详细说明
- mongodb集群方案:Replica Set集群的安装配置
- JavaScript内存管理
- HTML5labels属性
- 图像特征之SIFT特征匹配
- 数据驱动型企业如何炼成?只需五步!
- Android DiskLruCache(磁盘缓存)
- 1.Echarts饼状图详解及示例