Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tune/edit/add/change the kafka docker container parameters outside from the container

We have kafka docker container as the following ( on Linux redhat 7.5 )

We created the kafka service on the container according to - https://docs.confluent.io/5.0.0/installation/docker/docs/installation/single-node-client.html

docker-compose ps
               Name                           Command            State                     Ports
-------------------------------------------------------------------------------------------------------------------
kafka-single-node_kafka_1            /etc/confluent/docker/run   Up      0.0.0.0:9092->9092/tcp

docker ps
CONTAINER ID        IMAGE                                             COMMAND                  CREATED             STATUS              PORTS                                        NAMES
     0.0.0.0:8081->8081/tcp                       kafka-single-node_schemaregistry_1
de584963bb5a        confluentinc/cp-kafka:latest                      "/etc/confluent/dock…"   6 hours ago         Up 6 hours          0.0.0.0:9092->9092/tcp                       kafka-single-node_kafka_1

about - docker-compose.yml

pwd
/home/cp-docker-images/examples/kafka-single-node

more docker-compose.yml

kafka:
    image: confluentinc/cp-kafka:latest
    depends_on:
      - zookeeper
    ports:
      - 9092:9092
    environment:
      KAFKA_BROKER_ID: 1
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092
      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
      KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1

We want to control the kafka docker container configuration - /etc/kafka/server.properties outside from the container , ( or from the OS itself )

Let say I want to add some parameters or to change some parameters in server.properties ( of the kafka container )

so what is the best why to do the configuration outside from the kafka container

In the following example I show how to access the server.properties , inside The docker kafka container

docker exec -it de584963bb5a    bash

Now we can access/read the file - server.properties

root@de584963bb5a:/# more /etc/kafka/server.properties
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# see kafka.server.KafkaConfig for additional details and defaults

############################# Server Basics #############################

# The id of the broker. This must be set to a unique integer for each broker.
broker.id=0

############################# Socket Server Settings #############################

# The address the socket server listens on. It will get the value returned from
# java.net.InetAddress.getCanonicalHostName() if not configured.
#   FORMAT:
#     listeners = listener_name://host_name:port
#   EXAMPLE:
#     listeners = PLAINTEXT://your.host.name:9092
#listeners=PLAINTEXT://:9092
.
.
.

##################### Confluent Proactive Support ######################
# If set to true, and confluent-support-metrics package is installed
# then the feature to collect and report support metrics
# ("Metrics") is enabled.  If set to false, the feature is disabled.
#
confluent.support.metrics.enable=true


# The customer ID under which support metrics will be collected and
# reported.
#
# When the customer ID is set to "anonymous" (the default), then only a
# reduced set of metrics is being collected and reported.
#
# Confluent customers
# -------------------
# If you are a Confluent customer, then you should replace the default
# value with your actual Confluent customer ID.  Doing so will ensure
# that additional support metrics will be collected and reported.
#
confluent.support.customer.id=anonymous

############################# Group Coordinator Settings #############################

# The following configuration specifies the time, in milliseconds, that the GroupCoordinator will delay the initial consumer rebalance.
# The rebalance will be further delayed by the value of group.initial.rebalance.delay.ms as new members join the group, up to a maximum of max.poll.interval.ms.
# The default value for this is 3 seconds.
# We override this to 0 here as it makes for a better out-of-the-box experience for development and testing.
# However, in production environments the default value of 3 seconds is more suitable as this will help to avoid unnecessary, and potentially expensive, rebalances during application startu
p.
group.initial.rebalance.delay.ms=0
like image 419
jessica Avatar asked Sep 12 '25 01:09

jessica


1 Answers

We want to control the kafka docker container configuration - /etc/kafka/server.properties outside from the container

I would avoid mounting a server.properties file from the host since every setting within the container can be configured by environment variables like KAFKA_(variable) - https://docs.confluent.io/current/installation/docker/config-reference.html#confluent-kafka-configuration

Rather, you can use env_file for the compose file and move all your variables there

kafka:
   image: confluentinc/cp-kafka:latest
    depends_on:
      - zookeeper
    ports:
      - 9092:9092
    env_file:
      - broker1.env

broker1.env

KAFKA_BROKER_ID=1
KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181
KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka:9092
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_INTER_BROKER_LISTENER_NAME=PLAINTEXT
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1

And you can add any broker config with this pattern - https://kafka.apache.org/documentation/#brokerconfigs

like image 58
OneCricketeer Avatar answered Sep 13 '25 14:09

OneCricketeer