version: '3.5'
services:
  # ------------------------------------------------
  # ------------------- Zabbix Server --------------
  # ------------------------------------------------
  zabbix-server:
    image: zabbix/zabbix-server-mysql:alpine-6.2-latest
    container_name: zabbix-server
    restart: always
    ports:
      - 10051:10051/tcp
        #    dns:
        # - 10.10.10.111
        # - 10.10.10.222
        #dns_search: 
        #- vinos.local
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /etc/timezone:/etc/timezone:ro
      - ./state/usr/lib/zabbix/alertscripts:/usr/lib/zabbix/alertscripts:ro
      - ./state/usr/lib/zabbix/externalscripts:/usr/lib/zabbix/externalscripts:ro
      - ./state/var/lib/zabbix/export:/var/lib/zabbix/export:rw
      - ./state/var/lib/zabbix/modules:/var/lib/zabbix/modules:ro
      - ./state/var/lib/zabbix/enc:/var/lib/zabbix/enc:ro
      - ./state/var/lib/zabbix/ssh_keys:/var/lib/zabbix/ssh_keys:ro
      - ./state/var/lib/zabbix/mibs:/var/lib/zabbix/mibs:ro
      - ./state/var/lib/zabbix/snmptraps:/var/lib/zabbix/snmptraps:rw
      - ./env/odbc.ini:/etc/odbc.ini:ro
      - ./env/odbcinst.ini:/etc/odbcinst.ini:ro
    env_file:
      - ./env/database.env
      - ./env/server.env
    secrets:
      - MYSQL_USER
      - MYSQL_PASSWORD
      - MYSQL_ROOT_PASSWORD
    depends_on:
      - database
    stop_grace_period: 30s
    sysctls:
      - net.ipv4.ip_local_port_range=1024 65000
      - net.ipv4.conf.all.accept_redirects=0
      - net.ipv4.conf.all.secure_redirects=0
      - net.ipv4.conf.all.send_redirects=0
 #   networks:
  #    zabbix:
   #     ipv4_address: 10.10.254.118
  # ------------------------------------------------
  # ------------------- Zabbix Web -----------------
  # ------------------------------------------------
  zabbix-web:
    image: zabbix/zabbix-web-nginx-mysql:alpine-6.2-latest
    container_name: zabbix-web
    restart: always
    ports:
      - 80:8080/tcp
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /etc/timezone:/etc/timezone:ro
      - ./state/etc/ssl/nginx:/etc/ssl/nginx:ro
      - ./state/usr/share/zabbix/modules/:/usr/share/zabbix/modules/:ro
    env_file:
      - ./env/database.env
      - ./env/web.env
    secrets:
      - MYSQL_USER
      - MYSQL_PASSWORD
    depends_on:
      - database
      - zabbix-server
    sysctls:
      - net.core.somaxconn=65535
 #   networks:
  #    zabbix:
   #     ipv4_address: 10.10.254.119
  # ------------------------------------------------
  # ------------------- Zabbix Agent ---------------
  # ------------------------------------------------
  zabbix-agent2:
    image: zabbix/zabbix-agent2:alpine-6.2-latest
    container_name: zabbix-agent2
    restart: always
     #ports:
     #   - 10050:10050/tcp
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /etc/timezone:/etc/timezone:ro
      - ./state/etc/zabbix/zabbix_agentd.d:/etc/zabbix/zabbix_agentd.d:ro
      - ./state/var/lib/zabbix/modules:/var/lib/zabbix/modules:ro
      - ./state/var/lib/zabbix/enc:/var/lib/zabbix/enc:ro
      - ./state/var/lib/zabbix/ssh_keys:/var/lib/zabbix/ssh_keys:ro
    env_file:
      - ./env/agent.env
 #   networks:
  #    zabbix:
   #     ipv4_address: 10.10.254.120
  # ------------------------------------------------
  # ------------------- Zabbix SNMP Traps ----------
  # ------------------------------------------------
  zabbix-snmptraps:
    image: zabbix/zabbix-snmptraps:alpine-6.2-latest
    container_name: zabbix-snmptraps
    restart: always
    ports:
      - 162:1162/udp
    volumes:
      - ./state/var/lib/zabbix/snmptraps:/var/lib/zabbix/snmptraps:rw
    stop_grace_period: 5s
 #   networks:
  #    zabbix:
   #     ipv4_address: 10.10.254.121
  # ------------------------------------------------
  # ------------------- Zabbix Web Service ---------
  # ------------------------------------------------
  zabbix-web-service:
    image: zabbix/zabbix-web-service:alpine-6.2-latest
    container_name: zabbix-web-service
    restart: always
    volumes:
      - ./state/var/lib/zabbix/enc:/var/lib/zabbix/enc:ro
    cap_add:
      - SYS_ADMIN
    env_file:
      - ./env/web_service.env
    stop_grace_period: 5s
 #   networks:
  #    zabbix:
   #     ipv4_address: 10.10.254.122
  # ------------------------------------------------
  # ------------------- Database -------------------
  # ------------------------------------------------
  database:
    image: mariadb:10.6
    command: ['mysqld', '--collation_server=utf8_bin', '--character_set_server=utf8']
    container_name: database
    restart: always
    volumes:
      - ./state/var/lib/mysql:/var/lib/mysql:rw
      - ./zabbixdb-backup-restore-master:/home/zabbixdb-backup-restore-master:rw
    env_file:
      - ./env/database.env
    secrets:
      - MYSQL_USER
      - MYSQL_PASSWORD
      - MYSQL_ROOT_PASSWORD
    stop_grace_period: 1m
 #   networks:
  #    zabbix:
   #     ipv4_address: 10.10.254.123
  # ------------------------------------------------
  # ------------------- Watchtower -----------------
  # ------------------------------------------------
  watchtower:
    image: containrrr/watchtower
    container_name: watchtower
    restart: unless-stopped
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /etc/timezone:/etc/timezone:ro
      - /var/run/docker.sock:/var/run/docker.sock
    environment:
      WATCHTOWER_POLL_INTERVAL: "259200" # every 3rd day
      WATCHTOWER_CLEANUP: "true"
      WATCHTOWER_DEBUG: "true"

# ------------------------------------------------
# ------------------- Secrets --------------------
# ------------------------------------------------
# Note: chown -R root:root secrets && chmod 0700 secrets
secrets:
  MYSQL_USER:
    file: ./secrets/MYSQL_USER
  MYSQL_PASSWORD:
    file: ./secrets/MYSQL_PASSWORD
  MYSQL_ROOT_PASSWORD:
    file: ./secrets/MYSQL_ROOT_PASSWORD


#networks:
 # zabbix:
  #  external: true
   # driver: bridge
    #ipam:
     #config:
      # - subnet: 10.10.254.0/24
