version: '3.8'  

services:
  jobmanager:
    image: flink:1.18.0
    container_name: flink-jobmanager
    ports:
      - "8081:8081"  # Expose the JobManager UI on port 8081
    networks:
      - flink-network
    command: jobmanager
    environment:
      - JOB_MANAGER_RPC_ADDRESS=flink-jobmanager  # This should be the service name

  taskmanager:
    image: flink:1.18.0
    container_name: flink-taskmanager
    networks:
      - flink-network
    depends_on:
      - jobmanager  # Ensure JobManager starts before TaskManager
    command: taskmanager
    environment:
      - JOB_MANAGER_RPC_ADDRESS=flink-jobmanager  # This should match the JobManager service name
      - TASK_MANAGER_NUMBER_OF_TASK_SLOTS=4  # Adjust according to your resources

networks:
  flink-network:
    name: flink-network
    driver: bridge