您的位置:首页 > 运维架构 > Docker

使用Graylog2收集Docker日志

2017-08-09 00:00 423 查看
To find the current default logging driver for the Docker daemon, run docker info and search for Logging Driver. You can use the following command on Linux, macOS, or PowerShell on Windows:

-- https://docs.docker.com/engine/admin/logging/gelf/

-- https://docs.docker.com/engine/admin/logging/overview/

To use the
gelf
driver as the default logging driver, set the
log-driver
and
log-opt
keys to appropriate values in the
daemon.json
file, which is located in
/etc/docker/
on Linux hosts

To use
gelf
as the default logging driver for new containers, pass the
--log-driver
and
--log-opt
options to the Docker daemon:

dockerd
-–log-driver gelf –-log-opt gelf-address=udp://1.2.3.4:12201 \


To make the configuration permanent, you can configure it in
/etc/docker/daemon.json
:

{
"log-driver": "gelf",
"log-opts":  {
"gelf-address": "udp://1.2.3.4:12201"
"tag": "container"
}
}


You can set the logging driver for a specific container by setting the
--log-driver
flag when using
docker create
or
docker run
:

$ docker run \
-–log-driver gelf –-log-opt gelf-address=udp://1.2.3.4:12201 \
alpine echo hello world


You can try with this working example yaml:

example:
container_name: example
image: debian:wheezy
command: /bin/sh -c "while true; do date && echo "hello"; sleep 1; done"
ports:
- "1234:1234"
log_driver: "gelf"
log_opt:
gelf-address: "udp://graylog.example.com:12201"
gelf-tag: "first-logs"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  graylog docker