1

I'm trying to cap the max size of docker's log files. Each container's log file should max out at 100M. So each container such as the edge, worker, etc should only be allowed to have a log file that is 100MB.

I tried to insert:

log_opt:
    max-size: 100m

At the end of my docker-compose.yml file below but i'm getting an error. Where should I place it?. Also when I place it inside each container definition I'm getting an error. I read the docker docs but no where does it say where exactly to place the option.

This is my docker-compose.yml file:

version: '2.0'
services:
  ubuntu:
    image: ubuntu
    volumes:
      - box:/box
  cache:
    image: redis:3.0
  rabbitmq:
    image: rabbitmq:3-management
    volumes:
      - ${DATA}/rabbitmq:/var/lib/rabbitmq
    ports:
      - "15672:15672"
      - "5672:5672"
  placements-store:
    image: redis:3.0
    command: redis-server ${REDIS_OPTIONS}
    ports:
      - "6379:6379"
  api:
    image: ruby:2.3
    command: bundle exec puma -C config/puma.rb
    env_file:
      - ./.env
    working_dir: /app
    volumes:
      - .:/app/
      - box:/box
    expose:
      - 3000
    depends_on:
      - cache
      - placements-store
  worker:
    image: ruby:2.3
    command: bundle exec sidekiq -C ./config/schedule.yml -q default -q high_priority,5 -c 10
    env_file:
      - ./.env
    working_dir: /app
    environment:
      INSTANCE_TYPE: worker
    volumes:
      - .:/app/
      - box:/box
    depends_on:
      - cache
      - placements-store
  sidekiq-monitor:
    image: ruby:2.3
    command: bundle exec thin start -R sidekiq.ru -p 9494
    env_file:
      - ./.env
    working_dir: /app
    volumes:
      - .:/app/
      - box:/box
    depends_on:
      - cache
    expose:
      - 9494
  sneakers:
    image: ruby:2.3
    command: bundle exec rails sneakers:run
    env_file:
      - ./.env
    working_dir: /app
    environment:
      INSTANCE_TYPE: worker
    volumes:
      - .:/app/
      - box:/box
    depends_on:
      - cache
      - placements-store
      - rabbitmq
  edge:
    image: ruby:2.3
    command: bundle exec thin start -R config.ru -p 3000
    environment:
      REDIS_URL: redis://placements-store
      RACK_ENV: development
      BUNDLE_PATH: /box
      RABBITMQ_HOST: rabbitmq
    working_dir: /app
    volumes:
      - ./edge:/app/
      - box:/box
    depends_on:
      - placements-store
      - rabbitmq
    expose:
      - 3000
  proxy:
    image: openresty/openresty:latest-xenial
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./config/nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf
volumes:
  box:
  # node_modules:
  # bower_components:
  # client_dist:

This is what I tried, for example inserting under the rabbitmq container:

version: '2.0'
services:
  ubuntu:
    image: ubuntu
    volumes:
      - box:/box
  cache:
    image: redis:3.0
  rabbitmq:
    image: rabbitmq:3-management
    #volumes:
    #  - ${DATA}/rabbitmq:/var/lib/rabbitmq
    ports:
      - "15672:15672"
      - "5672:5672"
    log_opt:
      max-size: 50m
  placements-store:
    image: redis:3.0
    command: redis-server ${REDIS_OPTIONS}
    ports:
      - "6379:6379"

This is the error I get:

ERROR: The Compose file './docker-compose.yml' is invalid because: Unsupported config option for services.rabbitmq: 'log_opt'

Tried to change log_opt: with options: and got the same error:

ERROR: The Compose file './docker-compose.yml' is invalid because: Unsupported config option for services.rabbitmq: 'options'

Also the docker version is:

docker --version && docker-compose --version
Docker version 1.11.2, build b9f10c9/1.11.2
docker-compose version 1.9.0, build 2585387

UPDATE:

Tried using the logging option like the doc says (for version 2.0):

version: '2.0'
services:
  ubuntu:
    image: ubuntu
    volumes:
      - box:/box
  cache:
    image: redis:3.0
  rabbitmq:
    image: rabbitmq:3-management
    #volumes:
    #  - ${DATA}/rabbitmq:/var/lib/rabbitmq
    ports:
      - "15672:15672"
      - "5672:5672"
    logging:
      driver: "json-file"
      options:
        max-size: 100m
        max-file: 1
  placements-store:
    image: redis:3.0
    command: redis-server ${REDIS_OPTIONS}
    ports:
      - "6379:6379"

Getting the error:

ERROR: for rabbitmq Cannot create container for service rabbitmq: json: cannot unmarshal number into Go value of type string ERROR: Encountered errors while bringing up the project.

user2915097
  • 30,758
  • 6
  • 57
  • 59
Tom
  • 9,275
  • 25
  • 89
  • 147
  • while `docker run`has a max_size, see https://docs.docker.com/engine/admin/logging/overview/, I have been unable to find it for docker-compose in the docs at https://docs.docker.com/compose/compose-file/#/logging maybe it was removed, as I find it here https://forums.docker.com/t/how-to-specify-max-log-json-file-size-in-docker-compose/20873/3 – user2915097 Feb 13 '17 at 08:32
  • @user2915097 yes but the log_opt isn't working. – Tom Feb 13 '17 at 08:32
  • in https://forums.docker.com/t/how-to-specify-max-log-json-file-size-in-docker-compose/20873/3 there is indentation that you do not have, maybe that is the problem, as often with yaml files – user2915097 Feb 13 '17 at 08:34
  • @user2915097 see my update question. – Tom Feb 13 '17 at 09:06
  • according to http://stackoverflow.com/questions/33017329/where-is-a-log-file-with-logs-from-a-container you have to add `log_driver: "json-file" log_opt: max-size: "100k" max-file: "20"` maybe you need to add json-file before log_opt? – user2915097 Feb 13 '17 at 09:23
  • from https://docs.docker.com/compose/compose-file/#/logging it seems you have to specify a logginf driver, one of `driver: "json-file" driver: "syslog" driver: "none"` – user2915097 Feb 13 '17 at 09:25

0 Answers0