自訂日誌驅動程式輸出


tag 日誌選項指定如何格式化用於識別容器日誌訊息的標籤。預設情況下,系統使用容器 ID 的前 12 個字元。若要覆寫此行為,請指定 tag 選項。

$ docker run --log-driver=fluentd --log-opt fluentd-address=myhost.local:24224 --log-opt tag="mailer"

Docker 支援一些特殊的模板標記,您可以在指定標籤值時使用這些標記。

標記描述
{{.ID}}容器 ID 的前 12 個字元。
{{.FullID}}完整的容器 ID。
{{.Name}}容器名稱。
{{.ImageID}}容器映像檔 ID 的前 12 個字元。
{{.ImageFullID}}容器的完整映像檔 ID。
{{.ImageName}}容器所使用映像檔的名稱。
{{.DaemonName}}Docker 程式的名稱 (docker)。

例如,指定 --log-opt tag="{{.ImageName}}/{{.Name}}/{{.ID}}" 的值,會產生如下的 syslog 日誌行:

Aug  7 18:33:19 HOSTNAME hello-world/foobar/5790672ab6a0[9103]: Hello from Docker.

在啟動時,系統會在標籤中設定 container_name 欄位和 {{.Name}}。如果您使用 docker rename 重新命名容器,新名稱不會反映在日誌訊息中。相反地,這些訊息將繼續使用原始的容器名稱。

© . This site is unofficial and not affiliated with Kubernetes or Docker Inc.