Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker compose global level logging

I know for the latest docker compose, we can specify logging on a per service basis. eg :-

version: '2'

services:
  Sachin:
   image: hike/ubuntu:14.04
   volumes:
     - .:/testDocker
   working_dir: /testDocker
   logging:
    driver: "json-file"
    options:
     max-size: "25m"
     max-file: "2"
command: python -u test.py

I have a large number of containers in my compose file. I can specify the logging config for the docker daemon itself. I just wanted to know if it is possible to specify the logging configuration on the global level for the docker compose file. Something like this

version: '2'

services:
  Sachin:
   image: hike/ubuntu:14.04
   volumes:
     - .:/testDocker
   working_dir: /testDocker
logging:
 driver: "json-file"
 options:
  max-size: "25m"
  max-file: "2"
command: python -u test.py
like image 620
Sachin Malhotra Avatar asked Jul 25 '16 12:07

Sachin Malhotra


2 Answers

You could also configure the Docker default for this, all your container will have the configuration (that you can override per container).

Here an example of solution with YAML anchor:

version: "2"

services:

  proxy:
    build: proxy
    image: kinoulink/proxy
    ports:
      - 80:80
      - 443:443
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
    container_name: ktv_manager_proxy
    environment:
        - HTTP_AUTH_PASSWORD=$KTV_MANAGER_PASSWORD
    logging: &logging
      driver: "awslogs"
      options:
      awslogs-region: eu-west-1
      awslogs-group: docker

  rancher:
    image: rancher/server:v1.1.3
    volumes:
      - rancher_mysql:/var/lib/mysql
      - rancher_cattle:/var/lib/cattle
    labels:
      ktv.infra.proxy.domain: 'rancher'
      ktv.infra.proxy.port: '8080'
    logging:
      <<: *logging

From v3.4 (as @tekHedd said), you can use "extension field" syntax:

version: "3.4"

x-logging: 
      &default-logging
      driver: "awslogs"
      options:
      awslogs-region: eu-west-1
      awslogs-group: docker

services:
proxy:
    build: proxy
    image: kinoulink/proxy
    ports:
      - 80:80
      - 443:443
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
    container_name: ktv_manager_proxy
    environment:
        - HTTP_AUTH_PASSWORD=$KTV_MANAGER_PASSWORD
    logging: *default-logging

  rancher:
    image: rancher/server:v1.1.3
    volumes:
      - rancher_mysql:/var/lib/mysql
      - rancher_cattle:/var/lib/cattle
    labels:
      ktv.infra.proxy.domain: 'rancher'
      ktv.infra.proxy.port: '8080'
    logging: *default-logging
like image 61
Thomas Decaux Avatar answered Sep 30 '22 13:09

Thomas Decaux


It is not possible at this time. You can use YAML anchors to inject the same struct into each service instead of repeating it.

like image 30
dnephin Avatar answered Sep 30 '22 12:09

dnephin