version: '3.5'
services:
  # ------------------------------------------------
  # ------------------- Zabbix Server --------------
  # ------------------------------------------------
  zabbix-server:
    #image: zabbix/zabbix-server-mysql:alpine-7.0-latest
    logging:
      driver: loki
      options:
        loki-url: "http://localhost:3100/loki/api/v1/push"
    build:
     context: ./build
     dockerfile: Dockerfile
    container_name: zabbix-server
    restart: unless-stopped
    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
      - /home/icke/zabbix-server/state/usr/lib/zabbix/alertscripts:/usr/lib/zabbix/alertscripts:ro
      - /home/icke/zabbix-server/state/usr/lib/zabbix/externalscripts:/usr/lib/zabbix/externalscripts:ro
      - /home/icke/zabbix-server/state/var/lib/zabbix/export:/var/lib/zabbix/export:rw
      - /home/icke/zabbix-server/state/var/lib/zabbix/modules:/var/lib/zabbix/modules:ro
      - /home/icke/zabbix-server/state/var/lib/zabbix/enc:/var/lib/zabbix/enc:ro
      - /home/icke/zabbix-server/state/var/lib/zabbix/ssh_keys:/var/lib/zabbix/ssh_keys:ro
      - /home/icke/zabbix-server/state/var/lib/zabbix/mibs:/var/lib/zabbix/mibs:ro
      - /home/icke/zabbix-server/state/var/lib/zabbix/snmptraps:/var/lib/zabbix/snmptraps:rw
      - /home/icke/zabbix-server/env/odbc.ini:/etc/odbc.ini:ro
      - /home/icke/zabbix-server/env/odbcinst.ini:/etc/odbcinst.ini:ro
      - /home/icke/zabbix-server/env/freetds.conf:/usr/local/etc/freetds.conf:ro
    links:
      - mysql-zabbix
    env_file:
      - /home/icke/zabbix-server/env/database.env
      - /home/icke/zabbix-server/env/server.env
      - /home/icke/zabbix-server/env/odbc.env
    secrets:
      - MYSQL_USER
      - MYSQL_PASSWORD
      - MYSQL_ROOT_PASSWORD
    depends_on:
      - mysql-zabbix
    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: 172.40.0.2
  # ------------------------------------------------
  # ------------------- Zabbix Web -----------------
  # ------------------------------------------------
  zabbix-web:
    image: zabbix/zabbix-web-nginx-mysql:alpine-7.0-latest
    container_name: zabbix-web
    restart: always
    ports:
      - 8092:8080/tcp
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /etc/timezone:/etc/timezone:ro
      - /home/icke/zabbix-server/state/etc/ssl/nginx:/etc/ssl/nginx:ro
      - /home/icke/zabbix-server/state/usr/share/zabbix/modules/:/usr/share/zabbix/modules/:ro
    env_file:
      - /home/icke/zabbix-server/env/database.env
      - /home/icke/zabbix-server/env/web.env
    secrets:
      - MYSQL_USER
      - MYSQL_PASSWORD
    depends_on:
      - mysql-zabbix
      - zabbix-server
    sysctls:
      - net.core.somaxconn=65535
    networks:
      zabbix:
        ipv4_address: 172.40.0.3
  # ------------------------------------------------
  # ------------------- Zabbix Agent ---------------
  # ------------------------------------------------
  zabbix-agent2:
    image: zabbix/zabbix-agent2:alpine-7.0-latest
    container_name: zabbix-agent2
    restart: unless-stopped
    ports:
      - 10050:10050/tcp
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /etc/timezone:/etc/timezone:ro
      - /home/icke/zabbix-server/state/etc/zabbix/zabbix_agentd.d/:/etc/zabbix/zabbix_agentd.d/:ro
      - /home/icke/zabbix-server/state/etc/zabbix/zabbix_agent2.d/UserParameters.conf:/etc/zabbix/zabbix_agent2.d/UserParameters.conf:ro
      - /home/icke/zabbix-server/state/var/lib/zabbix/modules:/var/lib/zabbix/modules:ro
      - /home/icke/zabbix-server/state/var/lib/zabbix/enc:/var/lib/zabbix/enc:ro
      - /home/icke/zabbix-server/state/var/lib/zabbix/ssh_keys:/var/lib/zabbix/ssh_keys:ro
    env_file:
      - /home/icke/zabbix-server/env/agent.env
    networks:
      zabbix:
        ipv4_address: 172.40.0.4
  # ------------------------------------------------
  # ------------------- Zabbix SNMP Traps ----------
  # ------------------------------------------------
  zabbix-snmptraps:
    image: zabbix/zabbix-snmptraps:alpine-7.0-latest
    container_name: zabbix-snmptraps
    restart: always
    ports:
      - 162:1162/udp
    volumes:
      - /home/icke/zabbix-server/state/var/lib/zabbix/snmptraps:/var/lib/zabbix/snmptraps:rw
    stop_grace_period: 5s
    networks:
      zabbix:
        ipv4_address: 172.40.0.5
  # ------------------------------------------------
  # ------------------- Zabbix Web Service ---------
  # ------------------------------------------------
  zabbix-web-service:
    image: zabbix/zabbix-web-service:alpine-7.0-latest
    container_name: zabbix-web-service
    restart: always
    volumes:
      - /home/icke/zabbix-server/state/var/lib/zabbix/enc:/var/lib/zabbix/enc:ro
    cap_add:
      - SYS_ADMIN
    env_file:
      - /home/icke/zabbix-server/env/web_service.env
    stop_grace_period: 5s
    networks:
      zabbix:
        ipv4_address: 172.40.0.6
  # ------------------------------------------------
  # ------------------- Database -------------------
  # ------------------------------------------------
  mysql-zabbix:
    image: mariadb:10.6
    command: ['mysqld', '--collation_server=utf8_bin', '--character_set_server=utf8']
    container_name: mysql-zabbix
    restart: always
    volumes:
      - /home/icke/zabbix-server/state/var/lib/mysql:/var/lib/mysql:rw
      - /home/icke/zabbix-server/zabbixdb-backup-restore-master:/home/zabbixdb-backup-restore-master:rw
    #ports:
    #  - 3306:3306
    env_file:
      - /home/icke/zabbix-server/env/database.env
    secrets:
      - MYSQL_USER
      - MYSQL_PASSWORD
      - MYSQL_ROOT_PASSWORD
    stop_grace_period: 1m
    networks:
      zabbix:
        ipv4_address: 172.40.0.7
  # ------------------------------------------------
  # ------------------- 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: /home/icke/zabbix-server/state/secrets/MYSQL_USER
  MYSQL_PASSWORD:
    file: /home/icke/zabbix-server/state/secrets/MYSQL_PASSWORD
  MYSQL_ROOT_PASSWORD:
    file: /home/icke/zabbix-server/state/secrets/MYSQL_ROOT_PASSWORD


networks:
  zabbix:
  #  external: true
    driver: bridge
    ipam:
     config:
       - subnet: 172.40.0.0/28
