version: '3.0'

services:

  # Mail server running on separate image
  mail:
    image: tvial/docker-mailserver:latest
    restart: always
    domainname: example.com
    volumes:
      - maildata:/var/mail
      - mailstate:/var/mail-state
      - ./.docker/dev/mail/config/:/tmp/docker-mailserver/
    environment:
      - ENABLE_SPAMASSASSIN=0
      - ENABLE_CLAMAV=0
      - ENABLE_FAIL2BAN=0
      - ENABLE_POSTGREY=0
      - ENABLE_MANAGESIEVE=1
      - ONE_DIR=1
      - DMS_DEBUG=0
    cap_add:
      - NET_ADMIN
      - SYS_PTRACE

  # MySQL database
  db:
    image: mysql:5.7
    hostname: db
    restart: always
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_USER=snappymail
      - MYSQL_PASSWORD=snappymail
      - MYSQL_DATABASE=snappymail
    volumes:
      - mysql:/var/lib/mysql
      
  # PHP FPM Server
  php:
    build:
      context: ./.docker/dev/php
    depends_on:
      - db
      - mail
    volumes:
      - ./:/var/www
      - ./.docker/dev/php/snappymail.ini:/usr/local/etc/php/conf.d/snappymail.ini

  # Nginx load balancer translating to PHP FPM
  nginx:
    image: nginx:latest
    hostname: nginx
    depends_on:
      - php
    ports:
      - "${HTTPS_PORT}:443"
      - "${HTTP_PORT}:80"
    volumes:
      - ./:/var/www
      - ./.docker/dev/nginx/ssl:/etc/nginx/ssl
      - ./.docker/dev/nginx/default.conf:/etc/nginx/conf.d/default.conf

volumes:
  mysql:
    driver: local
  maildata:
    driver: local
  mailstate:
    driver: local