docker-compose json日志记录驱动程序标签/环境

时间:2017-04-19 04:38:28

标签: json logging docker-compose attr

我一直在努力获取日志格式:

{"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”键。我做错了什么?

1 个答案:

答案 0 :(得分:3)

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

  1. 指定要在日志中显示的标签/环境变量
  2. 在容器上设置这些标签/环境变量
  3. 所以,要获得你想要的东西,你需要将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