--- version: '2' services: zookeeper: image: confluentinc/cp-zookeeper:6.2.0 hostname: zookeeper ports: - '32181:32181' environment: ZOOKEEPER_CLIENT_PORT: 32181 ZOOKEEPER_TICK_TIME: 2000 extra_hosts: - "moby:127.0.0.1" kafka: image: confluentinc/cp-enterprise-kafka:6.2.0 hostname: kafka ports: - '9092:9092' - '29092:29092' depends_on: - zookeeper environment: KAFKA_BROKER_ID: 1 KAFKA_ZOOKEEPER_CONNECT: zookeeper:32181 KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092 KAFKA_AUTO_CREATE_TOPICS_ENABLE: "false" KAFKA_METRIC_REPORTERS: io.confluent.metrics.reporter.ConfluentMetricsReporter CONFLUENT_METRICS_REPORTER_BOOTSTRAP_SERVERS: kafka:29092 CONFLUENT_METRICS_REPORTER_ZOOKEEPER_CONNECT: zookeeper:32181 CONFLUENT_METRICS_REPORTER_TOPIC_REPLICAS: 1 CONFLUENT_METRICS_ENABLE: 'true' CONFLUENT_SUPPORT_CUSTOMER_ID: 'anonymous' extra_hosts: - "moby:127.0.0.1" schema-registry: image: confluentinc/cp-schema-registry:6.2.0 hostname: schema-registry depends_on: - zookeeper - kafka ports: - '8081:8081' environment: SCHEMA_REGISTRY_HOST_NAME: schema-registry SCHEMA_REGISTRY_KAFKASTORE_CONNECTION_URL: zookeeper:32181 extra_hosts: - "moby:127.0.0.1" # This "container" is a workaround to pre-create topics for the Kafka Music application # until we have a more elegant way to do that. kafka-create-topics: image: confluentinc/cp-kafka:6.2.0 depends_on: - kafka hostname: kafka-create-topics # We defined a dependency on "kafka", but `depends_on` will NOT wait for the # dependencies to be "ready" before starting the "kafka-create-topics" # container; it waits only until the dependencies have started. Hence we # must control startup order more explicitly. # See https://docs.docker.com/compose/startup-order/ command: "bash -c 'echo Waiting for Kafka to be ready... && \ cub kafka-ready -b kafka:29092 1 20 && \ kafka-topics --create --topic play-events --if-not-exists --zookeeper zookeeper:32181 --partitions 4 --replication-factor 1 && \ kafka-topics --create --topic song-feed --if-not-exists --zookeeper zookeeper:32181 --partitions 4 --replication-factor 1 && \ sleep infinity'" environment: # The following settings are listed here only to satisfy the image's requirements. # We override the image's `command` anyways, hence this container will not start a broker. KAFKA_BROKER_ID: ignored KAFKA_ZOOKEEPER_CONNECT: ignored extra_hosts: - "moby:127.0.0.1" # Continuously generates input data for the Kafka Music application. kafka-music-data-generator: image: confluentinc/kafka-streams-examples:6.2.0 hostname: kafka-music-data-generator depends_on: - kafka - schema-registry - kafka-create-topics # Control startup order similarly to the "kafka-create-topics" container above. command: "bash -c 'echo Waiting for Kafka to be ready... && \ cub kafka-ready -b kafka:29092 1 20 && \ echo Waiting for Confluent Schema Registry to be ready... && \ cub sr-ready schema-registry 8081 20 && \ java -cp /usr/share/java/kafka-streams-examples/kafka-streams-examples-6.2.0-standalone.jar \ io.confluent.examples.streams.interactivequeries.kafkamusic.KafkaMusicExampleDriver \ kafka:29092 http://schema-registry:8081'" environment: STREAMS_BOOTSTRAP_SERVERS: ignored STREAMS_SCHEMA_REGISTRY_HOST: ignored STREAMS_SCHEMA_REGISTRY_PORT: ignored KAFKA_MUSIC_APP_REST_HOST: ignored KAFKA_MUSIC_APP_REST_PORT: ignored extra_hosts: - "moby:127.0.0.1" # Runs the Kafka Music application. kafka-music-application: image: confluentinc/kafka-streams-examples:6.2.0 hostname: kafka-music-application depends_on: - kafka - schema-registry - kafka-create-topics # Control startup order similarly to the "kafka-create-topics" container above. # Note: The container's `run` script will perform the same readiness checks # for Kafka and Confluent Schema Registry, but that's ok because they complete fast. # The reason we check for readiness here is that we can insert a sleep time # for topic creation before we start the application. # # TODO: Once https://issues.apache.org/jira/browse/KAFKA-5037 is resolved, # we can remove this `command` and use the image as-is. command: "bash -c 'echo Waiting for Kafka to be ready... && \ cub kafka-ready -b kafka:29092 1 20 && \ echo Waiting for Confluent Schema Registry to be ready... && \ cub sr-ready schema-registry 8081 20 && \ echo Waiting a few seconds for topic creation to finish... && \ sleep 2 && \ /etc/confluent/docker/run'" ports: - '7070:7070' environment: STREAMS_BOOTSTRAP_SERVERS: kafka:29092 STREAMS_SCHEMA_REGISTRY_HOST: schema-registry STREAMS_SCHEMA_REGISTRY_PORT: 8081 KAFKA_MUSIC_APP_REST_HOST: kafka-music-application KAFKA_MUSIC_APP_REST_PORT: 7070 extra_hosts: - "moby:127.0.0.1"