services:
  php:
    build: ./code/
    expose:
      - 9000

  websocket:
    build: ./code/
    command: sh -c "composer install && php /var/www/html/ws/Ws.php"
    ports:
      - "8080:8080"
    depends_on:
      - db

  db:
    image: mysql:latest
    container_name: mysql
    environment:
      MYSQL_ROOT_PASSWORD: pass123
      MYSQL_DATABASE: mydb
      MYSQL_USER: myuser
      MYSQL_PASSWORD: pass123
    ports:
      - "3306:3306"
    restart: unless-stopped
    volumes:
      - ./mysql:/docker-entrypoint-initdb.d

  nginx:
    build:
      context: .
      dockerfile: ./nginx/Dockerfile
    ports:
      - 80:80
    volumes: # Add this section
      - ./code:/var/www/html # Mount your local code directory into Nginx's web root
    depends_on:
      - websocket
      - php # Add php dependency to ensure php is up before nginx tries to connect
