version: '3.9'

networks:
  app-network:
    driver: bridge

services:

  db:
    image: mysql:8.0
    container_name: laravel_db
    restart: always
    command: --default-authentication-plugin=mysql_native_password
    ports:
      - 3306:3306
    environment:
      MYSQL_DATABASE: ${DB_DATABASE}
      MYSQL_USER: ${DB_USERNAME}
      MYSQL_PASSWORD: ${DB_PASSWORD}
      MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
    volumes:
      - ./mysql:/var/lib/mysql
    networks:
      - app-network
  
  redis:
    image: redis:alpine3.16
    container_name: laravel_redis
    restart: unless-stopped
    ports:
      - 6379:6379
    volumes:
      - ./redis/data:/data
      - ./redis/redis.conf:/usr/local/etc/redis/redis.conf
    command: redis-server /usr/local/etc/redis/redis.conf
    networks:
      - app-network

  app:
    image: "laravel_basecode"
    build:
      context: .
      dockerfile: Dockerfile
    container_name: laravel_app
    restart: always
    command: bash -c "/wait && php artisan migrate && php artisan config:cache && apachectl -D FOREGROUND"
    ports:
      - 8000:80
    environment:
      - WAIT_HOSTS=db:3306
    depends_on:
      - db
    volumes:
      - ./public:/var/www/html/public 
    networks:
      - app-network