x-defaults: &defaults
  restart: unless-stopped
  logging:
    driver: json-file
    options:
      max-size: 100m
      max-file: '3'

services:
  zookeeper:
    <<: *defaults
    image: ${GLOBAL_REGISTRY:-}zookeeper:${ZOOKEEPER_VERSION:-3.9.3}
    ports:
      - '${ZOOKEEPER_CLIENT_PORT_OVERRIDE:-2181}:2181'
      - '${ZOOKEEPER_ADMIN_PORT_OVERRIDE:-8080}:8080'
    volumes:
      - zookeeper_data:/data
      - zookeeper_datalog:/datalog
      - zookeeper_logs:/logs
    environment:
      - TZ=${TZ:-UTC}
      - ZOO_MY_ID=1
      - ZOO_PORT=2181
      - ZOO_TICK_TIME=${ZOO_TICK_TIME:-2000}
      - ZOO_INIT_LIMIT=${ZOO_INIT_LIMIT:-10}
      - ZOO_SYNC_LIMIT=${ZOO_SYNC_LIMIT:-5}
      - ZOO_MAX_CLIENT_CNXNS=${ZOO_MAX_CLIENT_CNXNS:-60}
      - ZOO_4LW_COMMANDS_WHITELIST=${ZOO_4LW_COMMANDS_WHITELIST:-srvr,mntr,ruok}
    deploy:
      resources:
        limits:
          cpus: ${ZOOKEEPER_CPU_LIMIT:-1.0}
          memory: ${ZOOKEEPER_MEMORY_LIMIT:-1G}
        reservations:
          cpus: ${ZOOKEEPER_CPU_RESERVATION:-0.25}
          memory: ${ZOOKEEPER_MEMORY_RESERVATION:-512M}
    healthcheck:
      test: [CMD-SHELL, 'echo ruok | nc localhost 2181 | grep imok']
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 30s

volumes:
  zookeeper_data:
  zookeeper_datalog:
  zookeeper_logs:
