version: '3.0'
services:
  zk:
    image: zookeeper:3.6.1
    restart: always
    ports:
     - "2181:2181"
    volumes:
     - ./data/zk:/data

  bookie_init:
    image: apache/bookkeeper:4.10.0
    environment:
      BK_zkServers: "zk:2181"
      BK_advertisedAddress: ${BK_PUBLIC_IP}
    restart: on-failure
    depends_on:
      - zk
    command: /opt/bookkeeper/bin/bookkeeper shell metaformat -nonInteractive
        
  bookie:
    image: apache/bookkeeper:4.10.0
    restart: on-failure
    environment:
      BK_zkServers: "zk:2181"
      BK_advertisedAddress: ${BK_PUBLIC_IP}
      BK_httpServerPort: 3182      
    ports:
      - "3181:3181"
      - "3182:3182"
    volumes:
      - ./data/bk:/data
    depends_on:
      - zk
      - bookie_init

  bookie1:
    image: apache/bookkeeper:4.10.0
    restart: on-failure
    environment:
      BOOKIE_PORT: 4181
      BK_zkServers: "zk:2181"
      BK_advertisedAddress: ${BK_PUBLIC_IP}
      BK_httpServerPort: 3182      
    ports:
      - "4181:4181"
    volumes:
      - ./data/bk1:/data
    depends_on:
      - zk
      - bookie_init

  bookie2:
    image: apache/bookkeeper:4.10.0
    restart: on-failure
    environment:
      BOOKIE_PORT: 4182
      BK_zkServers: "zk:2181"
      BK_advertisedAddress: ${BK_PUBLIC_IP}
      BK_httpServerPort: 3182      
    ports:
      - "4182:4182"
    volumes:
      - ./data/bk2:/data
    depends_on:
      - zk
      - bookie_init