使用Graylog2收集Docker日誌

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:docker

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

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

 

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 this

  • 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"
相關文章
相關標籤/搜索