Skip to content

Instantly share code, notes, and snippets.

@dictcp
Last active March 23, 2021 03:56
Show Gist options
  • Save dictcp/e525b06e6e00f196fa79a260a8d84a7d to your computer and use it in GitHub Desktop.
Save dictcp/e525b06e6e00f196fa79a260a8d84a7d to your computer and use it in GitHub Desktop.
Quick demo on Fluentd logging driver in Docker

It is a demo on how to leverage on docker logs option to send logs to another server

docker-compose up -d

docker-compose restart web

docker-compose logs

## you will see the stdout from podinfo and go to fluentd stdout (due to the fluentd config), like
## fluentd_1  | 2021-03-23 03:51:58.000000000 +0000 7a3c12568bff: {"log":"Error to open config file, stat config.yaml: no such file or directory","container_id":"7a3c12568bff77f17a3909d63074401328af851e5d763a2b75b1e7e273c6ef33","container_name":"/test_web_1","source":"stdout"}
## fluentd_1  | 2021-03-23 03:51:58.000000000 +0000 7a3c12568bff: {"source":"stderr","log":"{\"level\":\"info\",\"ts\":\"2021-03-23T03:51:58.480Z\",\"caller\":\"podinfo/main.go:150\",\"msg\":\"Starting podinfo\",\"version\":\"5.2.0\",\"revision\":\"\",\"port\":\"9898\"}","container_id":"7a3c12568bff77f17a3909d63074401328af851e5d763a2b75b1e7e273c6ef33","container_name":"/test_web_1"}
## web_1      | Error to open config file, stat config.yaml: no such file or directory
## web_1      | {"level":"info","ts":"2021-03-23T03:51:43.991Z","caller":"podinfo/main.go:150","msg":"Starting podinfo","version":"5.2.0","revision":"","port":"9898"}
## web_1      | {"level":"info","ts":"2021-03-23T03:51:54.920Z","caller":"api/server.go:209","msg":"Shutting down HTTP/HTTPS server","timeout":5}
## web_1      | Error to open config file, stat config.yaml: no such file or directory
## web_1      | {"level":"info","ts":"2021-03-23T03:51:58.480Z","caller":"podinfo/main.go:150","msg":"Starting podinfo","version":"5.2.0","revision":"","port":"9898"}
services:
web:
image: stefanprodan/podinfo
ports:
- '9898:9898'
logging:
driver: fluentd
options:
fluentd-address: "127.0.0.1:24224"
depends_on:
- "fluentd"
fluentd:
image: fluent/fluentd:latest
ports:
- '24224:24224'
- '24224:24224/udp'
volumes:
- ./fluentd.conf:/fluentd/etc/fluentd.conf
environment:
- FLUENTD_CONF=fluentd.conf
<source>
@type forward
</source>
<match *>
@type stdout
</match>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment