DevOps

[Docker]Kafka + Zookeeper docker-compose Example

차노도리 2023. 5. 30. 00:04

docker-compose

  • 여러개의 컨테이너로부터 이루어진 서비스를 구축할때 사용한다.

 

Kafka docker-compose.yml 생성

  • kafka 브로커를 이용할때 정확한 IP가 필요해서 IP 설정 필요
version: '2'
services:
  zookeeper:
    image: gugbab/zookeeper
    ports:
      - "2181:2181"
    networks:
      my-network:
        ipv4_address: 172.18.0.100
  kafka:
    image: gugbab/kafka
    ports:
      - "9092:9092"
    environment:
      KAFKA_ADVERTISED_HOST_NAME: 172.18.0.100
      KAFKA_CREATE_TOPICS: "gugbab_test:1:1"
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    depends_on:
      - zookeeper
    networks:
      my-network:
        ipv4_address: 172.18.0.101

networks:
  my-network:
    name: gugbab-network

 

docker-compose 실행

  • docker-compose -f [파일명] up -d 

 

컨테이너 생성 결과