version: '3'
services:
  polaris-redis:
    image: ${REGISTRY}redis:latest  # 使用官方Redis镜像
    restart: unless-stopped
    healthcheck:
      test: [ "CMD", "redis-cli", "--raw", "incr", "ping" ]
      interval: 15s
      timeout: 5s
      retries: 10
      start_period: 10s
    networks:
      - media-net
    # ports:
    #   - 6379:6379
    volumes:
      - ./redis/conf/redis.conf:/opt/polaris/redis/redis.conf
      - ./volumes/redis/data/:/data
    environment:
      TZ: "Asia/Shanghai"
    command: redis-server /opt/polaris/redis/redis.conf --appendonly yes

  polaris-mysql:
    image: ${REGISTRY}mysql:8  # 使用官方MySQL 8镜像
    restart: unless-stopped
    healthcheck:
      test: [ "CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/3306" ]
      interval: 15s
      timeout: 5s
      retries: 10
      start_period: 10s
    networks:
      - media-net
    environment:
      MYSQL_DATABASE: wvp
      MYSQL_ROOT_PASSWORD: root
      MYSQL_USER: wvp_user
      MYSQL_PASSWORD: wvp_password
      TZ: Asia/Shanghai
    # ports:
    #   - 3306:3306
    volumes:
      - ./mysql/conf:/etc/mysql/conf.d
      - ./logs/mysql:/logs
      - ./volumes/mysql/data:/var/lib/mysql  
      - ../数据库/2.7.4/初始化-mysql-2.7.4.sql:/docker-entrypoint-initdb.d/init.sql  # 初始化SQL脚本目录
    command: [
          # '--default-authentication-plugin=mysql_native_password',
          '--innodb-buffer-pool-size=80M',
          '--character-set-server=utf8mb4',
          '--collation-server=utf8mb4_general_ci',
          '--default-time-zone=+8:00',
          '--lower-case-table-names=1'
        ]

  polaris-media:
    image: ${REGISTRY}zlmediakit/zlmediakit:latest  # 替换为官方镜像
    restart: always
    networks:
      - media-net
    ports:
     #- "6080:80/tcp"     # [播流]HTTP  安全考虑-非测试阶段需要注释掉，改为由nginx代理播流地址
     #- "4443:443/tcp"     # [播流]HTTPS 安全考虑-非测试阶段需要注释掉，改为由nginx代理播流地址
      - "${MediaRtmp:-10001}:10001/tcp"   # [收流]RTMP  宿主机端口可配置:容器端口固定
      - "${MediaRtmp:-10001}:10001/udp"   # [收流]RTMP
     #- "41935:41935/tcp"   # [收流]RTMPS 无效
      - "${MediaRtsp:-10002}:10002/tcp"     # [收流]RTSP  宿主机端口可配置:容器端口固定
      - "${MediaRtsp:-10002}:10002/udp"     # [收流]RTSP
     #- "45540:45540/tcp"   # [收流]RTSPS 无效
      - "${MediaRtp:-10003}:10003/tcp"   # [收流]RTP  宿主机端口可配置:容器端口固定
      - "${MediaRtp:-10003}:10003/udp"   # [收流]RTP   
    volumes:
      - ./volumes/video:/opt/media/bin/www/record/
      - ./logs/media:/opt/media/log/
      - ./media/config.ini:/conf/config.ini
    command: [
        'MediaServer',
        '-c', '/conf/config.ini',
        '-l', '0'
    ]

  polaris-wvp:
    image: ${REGISTRY}polaris-wvp:latest
    restart: always
    networks:
      - media-net
    ports:
      - "18978:18978"
      - "${SIP_Port:-8160}:8160/udp"
      - "${SIP_Port:-8160}:8160/tcp"
    depends_on:
      - polaris-redis
      - polaris-mysql
      - polaris-media
    volumes:
      - ./logs/wvp:/opt/wvp/logs/
    environment:
      TZ: "Asia/Shanghai"
      Stream_IP: ${Stream_IP:-127.0.0.1}
      # SDP里的IP
      SDP_IP: ${SDP_IP:-127.0.0.1}
      # [可选] zlm服务器访问WVP所使用的IP, 默认使用127.0.0.1，zlm和wvp没有部署在同一台服务器时必须配置
      ZLM_HOOK_HOST: polaris-wvp
      ZLM_HOST: polaris-media
      ZLM_SERCERT: su6TiedN2rVAmBbIDX0aa0QTiBJLBdcf

      MediaHttp: ${WebHttp:-8080}
      #MediaHttps: ${WebHttps:-443}
      MediaRtmp: ${MediaRtmp:-10001}
      MediaRtsp: ${MediaRtsp:-10002}
      MediaRtp: ${MediaRtp:-10003}

      REDIS_HOST: polaris-redis
      REDIS_PORT: 6379

      DATABASE_HOST: polaris-mysql
      DATABASE_PORT: 3306
      DATABASE_USER: wvp_user
      DATABASE_PASSWORD: wvp_password

      SIP_ShowIP: ${SIP_ShowIP:-127.0.0.1}
      SIP_Port: ${SIP_Port:-8160}
      SIP_Domain: ${SIP_Domain:-3502000000}
      SIP_Id: ${SIP_Id:-35020000002000000001}
      SIP_Password: ${SIP_Password:-wvp_sip_password}

      RecordSip: ${RecordSip:-true}
      RecordPushLive: ${RecordPushLive:-false}

  polaris-nginx:
    image: ${REGISTRY}polaris-nginx:latest
    restart: always
    ports:
      - "${WebHttp:-8080}:8080"
    depends_on:
      - polaris-wvp
    volumes:
      - ./nginx/templates/:/etc/nginx/templates
      - ./logs/nginx:/var/log/nginx
    environment:
      # 流链接的IP
      Stream_IP: ${Stream_IP}
    networks:
      - media-net
      
networks:
  media-net:
    driver: bridge