version: "3.8"

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
      network: host

    container_name: my_laravel_app
    ports:
      - "5000:80"
    volumes:
      - ./:/var/www/html
    networks:
      - my_bridge_network
    environment:
      - DB_CONNECTION=mysql
      - DB_HOST=db
      - DB_PORT=3306
      - DB_DATABASE=mydatabase
      - DB_USERNAME=root
      - DB_PASSWORD=my-secret-pw

    depends_on:
      db:
        condition: service_healthy

  db:
    image: mysql:8.0
    container_name: my_db
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: my-secret-pw
      MYSQL_DATABASE: mydatabase
      MYSQL_USER: myuser
      MYSQL_PASSWORD: mypassword
    ports:
      - "3306:3306"
    networks:
      - my_bridge_network
    volumes:
      - mysql_data:/var/lib/mysql
      - ./Docker/my.cnf:/etc/mysql/conf.d/my.cnf

    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
      interval: 20s
      retries: 10

  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    container_name: my_phpmyadmin
    restart: unless-stopped
    environment:
      PMA_HOST: db
      MYSQL_ROOT_PASSWORD: my-secret-pw
      UPLOAD_LIMIT: 1000M
    ports:
      - "5001:80"
    depends_on:
      db:
        condition: service_healthy
    networks:
      - my_bridge_network

volumes:
  mysql_data:

networks:
  my_bridge_network:
    driver: bridge
