【问题标题】:docker-compose json logging driver labels/envdocker-compose json 日志记录驱动程序标签/环境
【发布时间】:2017-04-19 04:38:28
【问题描述】:

我一直在尝试获取格式的日志:

{"log":"Using CATALINA_BASE:   /opt/apache-tomcat-
7.0.76\r\n","stream":"stdout","time":"2017-04-
19T04:28:33.608418994Z","attrs":
{"production_status":"testing","os":"ubuntu"}}

我正在使用 docker-compose.yml :

version: '2.1'
services:
  web:
    image: hello-world/web:latest
    container_name: api
    ports:
      - "80:8080"
logging:
  driver: "json-file"
  options:
    max-size: 10m
    max-file: "3"
    labels: testing
    env: ubuntu

但我没有在日志中获得“attrs”键。我做错了什么?

【问题讨论】:

  • 你知道了吗?

标签: json logging docker-compose attr


【解决方案1】:

根据我的测试,有 2 部分可以让标签/环境变量显示在日志中。

  1. 指定要在日志中显示的标签/环境变量
  2. 在容器上设置这些标签/环境变量

所以,要得到你想要的,你需要将 docker-compose.yml 设置为:

version: '2.1'
services:
  web:
    image: hello-world/web:latest
    container_name: api
    ports:
      - "80:8080"
    logging:
      driver: "json-file"
      options:
        max-size: 10m
        max-file: "3"
        labels: "production_status"
        env: "os"
    labels:
      production_status: "testing"
    environment:
      - os=ubuntu

【讨论】:

  • 如何在日志选项下指定多个标签?我无法让我的日志记录超过列表中的第一个标签。
  • @Mnebuerquo 只需将它们指定为逗号分隔,就像这里描述的 docs.docker.com/config/containers/logging/json-file 一样。例如 env:"os,version"
猜你喜欢
  • 1970-01-01
  • 2023-04-08
  • 2023-03-30
  • 2023-03-14
  • 1970-01-01
  • 1970-01-01
  • 2015-12-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多