networks:
  net:
    ipam:
      driver: default
      config:
        - subnet: ${DOCKER_IP_PREFIX}.0/24
services:
  mysql:
    restart: always
    build: ./docker/mysql
    volumes:
      - ${MYSQL_DATA_DIR}:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=${DB_PASSWORD}
      - MYSQL_DATABASE=${DB_DATABASE}
      - TZ=${TZ}
    deploy:
        replicas: ${ENABLE_MYSQL_SERVICE}
    networks:
      net:
        ipv4_address: ${DOCKER_IP_PREFIX}.2
  redis:
    restart: always
    build: ./docker/redis
    volumes:
      - ${REDIS_DATA_DIR}:/data
    environment:
      - TZ=${TZ}
    deploy:
        replicas: ${ENABLE_REDIS_SERVICE}
    networks:
      net:
        ipv4_address: ${DOCKER_IP_PREFIX}.3
  php-fpm:
    restart: always
    build:
      context: ./docker/php
    volumes:
      - .:/var/www
    environment:
      - TZ=${TZ}
#      - XDEBUG_CONFIG=client_host=${DOCKER_IP_PREFIX}.1
    user: "${PHP_FPM_UID}"
    networks:
      net:
        ipv4_address: ${DOCKER_IP_PREFIX}.4
  nginx:
    restart: always
    build: ./docker/nginx
    volumes:
      - .:/var/www
    depends_on:
      - php-fpm
    environment:
      - TZ=${TZ}
    entrypoint:
      [ "wait-for-it", "-s", "php-fpm:9000", "--", "nginx", "-g", "daemon off;" ]
    networks:
      net:
        ipv4_address: ${DOCKER_IP_PREFIX}.5
