{"id":122532,"date":"2025-02-11T08:52:10","date_gmt":"2025-02-11T08:52:10","guid":{"rendered":"\/tutorials\/?p=122532"},"modified":"2025-08-26T09:55:47","modified_gmt":"2025-08-26T09:55:47","slug":"how-to-deploy-kafka-on-docker","status":"publish","type":"post","link":"\/tutorials\/how-to-deploy-kafka-on-docker","title":{"rendered":"How to deploy Kafka on Docker"},"content":{"rendered":"<p>Apache Kafka is an open-source messaging system that can process, store, and move data quickly. Companies often use it to send vast numbers of messages in an organized queue, which people can access in real-time using their devices. It can be applied in everything, from inventory management to patient monitoring.<\/p><p>There are many ways to set up and run Kafka, but using Docker has several benefits, such as easier setup, better reproducibility, and improved scalability. That&rsquo;s because Docker containers allow you to package Kafka into isolated environments so that it doesn&rsquo;t interfere with the other applications on your server.<\/p><p>This guide will show you how to deploy an Apache Kafka cluster on an Ubuntu VPS using Docker. We&rsquo;ll cover each step, from setting up Docker to configuring and running Kafka containers.<\/p><p>\n\n\n\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-prerequisites\">Prerequisites<\/h2><p>Before you begin deploying Kafka on Docker, you&rsquo;ll need a hosting provider that offers the basic hardware requirements. We recommend a <a href=\"\/vps-hosting\">VPS server<\/a> with:<\/p><ul class=\"wp-block-list\">\n<li>At least <strong>4GB<\/strong> of <strong>RAM<\/strong> (<strong>16GB<\/strong> recommended for production)&nbsp;&nbsp;<\/li>\n\n\n\n<li><strong>2 CPU<\/strong> cores (<strong>4+ CPU<\/strong> cores needed for production)&nbsp;&nbsp;<\/li>\n\n\n\n<li><strong>500GB<\/strong> of disk space (SSDs are preferred for better speed)&nbsp;&nbsp;<\/li>\n<\/ul><p>Note that these requirements may vary depending on your specific use case and expected load. For development and testing purposes, you can start with the lower end of hardware specifications and scale up as needed.<\/p><p>A few other general prerequisites include:<\/p><ul class=\"wp-block-list\">\n<li>Ubuntu 24.04 pre-installed on your VPS server<\/li>\n\n\n\n<li>SSH access with root or sudo privileges<\/li>\n\n\n\n<li>A reliable network connection (1 GbE+ recommended)<\/li>\n\n\n\n<li>A basic understanding of <a href=\"\/tutorials\/docker-image-vs-container\">Docker concepts<\/a>, such as containers, images, and volumes<\/li>\n<\/ul><h2 class=\"wp-block-heading\" id=\"h-how-to-deploy-apache-kafka-on-docker\">How to deploy Apache Kafka on Docker<\/h2><p>Let&rsquo;s go over how to deploy Apache Kafka using Docker on an Ubuntu VPS. We&rsquo;ll walk you through each step, from setting up Docker Compose to testing your Kafka deployment.<\/p><h3 class=\"wp-block-heading\" id=\"h-1-set-up-your-environment\">1. Set up your environment<\/h3><p>First, ensure your VPS environment is properly configured and ready for Kafka deployment.<\/p><p>The easiest way to get started is using <a href=\"https:\/\/support.hostinger.com\/en\/articles\/8306612-how-to-use-the-docker-vps-template\" target=\"_blank\" rel=\"noopener\">Hostinger&rsquo;s Ubuntu 24.04 with Docker template<\/a>, which comes with Docker, Docker Engine, and Docker Compose pre-installed. But if you&rsquo;d rather do it manually, you can also install Docker on a regular Ubuntu VPS by following our <a href=\"\/tutorials\/how-to-install-docker-on-ubuntu\">comprehensive Docker setup guide<\/a>.<\/p><figure class=\"wp-block-image size-large\"><a class=\"hgr-tutorials-cta hgr-tutorials-cta-vps-hosting\" href=\"\/vps-hosting\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/public\" alt=\"\" class=\"wp-image-77934\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=768,fit=scale-down 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><p>To use the template on your VPS, follow these steps:<\/p><ol class=\"wp-block-list\">\n<li>Log in to hPanel and navigate to VPS &rarr; Manage.<\/li>\n\n\n\n<li>Go to Settings &rarr; OS &amp; Panel &rarr; Operating System.<\/li>\n\n\n\n<li>Select Application &rarr; Ubuntu 24.04 with Docker.<\/li>\n<\/ol><p>After this, you&rsquo;ll need to access your VPS server using a terminal to proceed with the rest of these steps. You can either do this using Hostinger&rsquo;s built-in Browser Terminal, or <a href=\"https:\/\/support.hostinger.com\/en\/articles\/5723772-how-to-connect-to-your-vps-via-ssh\" target=\"_blank\" rel=\"noopener\">connect to your VPS server via SSH<\/a> using Terminal on your Windows or Mac.<\/p><p>Once done, check if the latest versions of Docker and Docker Compose are installed on your system by running the following commands using the Terminal:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">docker --version\n\ndocker compose --version<\/pre><p>If, for some reason, Docker Compose is not already installed, you can install it now by running the following command:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo apt install docker compose-plugin<\/pre><p>Since the template pre-allocates resources depending on your VPS plan, you don&rsquo;t typically need to configure anything else.<\/p><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69e0031b42d2e\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" width=\"2493\" height=\"1274\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/02\/8.png\/public\" alt=\"Hostinger offers a pre-configured Ubuntu 24.04 Docker template.\" class=\"wp-image-122534\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/02\/8.png\/w=2493,fit=scale-down 2493w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/02\/8.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/02\/8.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/02\/8.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/02\/8.png\/w=768,fit=scale-down 768w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/02\/8.png\/w=1536,fit=scale-down 1536w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/02\/8.png\/w=2048,fit=scale-down 2048w\" sizes=\"(max-width: 2493px) 100vw, 2493px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><h3 class=\"wp-block-heading\" id=\"h-2-dockerize-apache-kafka\">2. Dockerize Apache Kafka<\/h3><p>Apache Kafka is a distributed system where different components work together smoothly. Kafka uses brokers to store and process messages, while <a href=\"https:\/\/zookeeper.apache.org\/\" target=\"_blank\" rel=\"noopener\">ZooKeeper<\/a> traditionally manages the cluster&rsquo;s metadata and coordinates the brokers. Each broker can handle thousands of reads and writes per second, making Kafka highly scalable for real-time data streaming.<\/p><p>The easiest way to deploy Kafka with Docker is by using the official Docker images from Confluent Inc. The <strong>confluentinc\/cp-kafka<\/strong> image provides Kafka&rsquo;s Community Version, and <strong>confluentinc\/cp-zookeeper<\/strong> offers the ZooKeeper service.<\/p><p>These Docker images make deployment easier by ensuring consistency across environments, simplifying configuration, and enabling easy scaling.<\/p><p>To get started, we need to first create the necessary directories for data persistence and set proper permissions:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">mkdir -p .\/kafka\/data .\/zookeeper\/data .\/zookeeper\/log\n\nchmod -R 777 .\/kafka .\/zookeeper<\/pre><p>To set up Kafka with Docker, you need to create a <strong>docker-compose.yml<\/strong> file. This file should be located in the root directory of your project inside the Ubuntu VPS (Example: \/kafka). More on that in the next step.<\/p><figure data-wp-context='{\"imageId\":\"69e0031b4365c\"}' data-wp-interactive=\"core\/image\" class=\"wp-block-image aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" width=\"2493\" height=\"1274\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/02\/3.png\/public\" alt=\"To get started, we need to first create the necessary directories for data persistence and set proper permissions.\n\" class=\"wp-image-122535\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/02\/3.png\/w=2493,fit=scale-down 2493w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/02\/3.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/02\/3.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/02\/3.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/02\/3.png\/w=768,fit=scale-down 768w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/02\/3.png\/w=1536,fit=scale-down 1536w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/02\/3.png\/w=2048,fit=scale-down 2048w\" sizes=\"(max-width: 2493px) 100vw, 2493px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><h3 class=\"wp-block-heading\" id=\"h-3-create-a-docker-compose-file\">3. Create a Docker Compose file<\/h3><p>The Docker Compose file serves as the blueprint for your Kafka deployment, defining all necessary services and their configurations. Create a new file named <strong>docker-compose.yml<\/strong> in your project directory and configure it with the following essential components:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">version: '3.8'\n\nnetworks:\n\n&nbsp;&nbsp;kafka-net:\n\n&nbsp;&nbsp;&nbsp;&nbsp;driver: bridge\n\nservices:\n\n&nbsp;&nbsp;zookeeper:\n\n&nbsp;&nbsp;&nbsp;&nbsp;image: confluentinc\/cp-zookeeper:7.8\n\n&nbsp;&nbsp;&nbsp;&nbsp;container_name: zookeeper\n\n&nbsp;&nbsp;&nbsp;&nbsp;ports:\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- \"2181:2181\"\n\n&nbsp;&nbsp;&nbsp;&nbsp;environment:\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ZOOKEEPER_CLIENT_PORT: 2181\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ZOOKEEPER_TICK_TIME: 2000\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ZOOKEEPER_INIT_LIMIT: 5\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ZOOKEEPER_SYNC_LIMIT: 2\n\n&nbsp;&nbsp;&nbsp;&nbsp;volumes:\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- zookeeper_data:\/var\/lib\/zookeeper\/data\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- zookeeper_log:\/var\/lib\/zookeeper\/log\n\n&nbsp;&nbsp;&nbsp;&nbsp;networks:\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- kafka-net\n\n&nbsp;&nbsp;&nbsp;&nbsp;healthcheck:\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;test: [\"CMD\", \"nc\", \"-z\", \"localhost\", \"2181\"]\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;interval: 30s\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;timeout: 10s\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;retries: 3\n\n&nbsp;&nbsp;kafka:\n\n&nbsp;&nbsp;&nbsp;&nbsp;image: confluentinc\/cp-kafka:7.8\n\n&nbsp;&nbsp;&nbsp;&nbsp;container_name: kafka\n\n&nbsp;&nbsp;&nbsp;&nbsp;depends_on:\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- zookeeper\n\n&nbsp;&nbsp;&nbsp;&nbsp;ports:\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- \"9092:9092\"\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- \"29092:29092\"\n\n&nbsp;&nbsp;&nbsp;&nbsp;environment:\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;KAFKA_BROKER_ID: 1\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;KAFKA_ADVERTISED_LISTENERS: PLAINTEXT:\/\/kafka:29092,PLAINTEXT_HOST:\/\/your-vps-ip:9092\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;KAFKA_LOG_DIRS: \"\/var\/lib\/kafka\/data\"\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;KAFKA_LOG_RETENTION_HOURS: 168\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;KAFKA_MESSAGE_MAX_BYTES: 1000000\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;KAFKA_AUTO_CREATE_TOPICS_ENABLE: \"true\"\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;KAFKA_DELETE_TOPIC_ENABLE: \"true\"\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;KAFKA_NUM_PARTITIONS: 3\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;KAFKA_DEFAULT_REPLICATION_FACTOR: 1\n\n&nbsp;&nbsp;&nbsp;&nbsp;volumes:\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- kafka_data:\/var\/lib\/kafka\/data\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- kafka_logs:\/var\/log\/kafka\n\n&nbsp;&nbsp;&nbsp;&nbsp;networks:\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- kafka-net\n\n&nbsp;&nbsp;&nbsp;&nbsp;healthcheck:\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;test: [\"CMD\", \"nc\", \"-z\", \"localhost\", \"9092\"]\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;interval: 30s\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;timeout: 10s\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;retries: 3\n\nvolumes:\n\n&nbsp;&nbsp;kafka_data:\n\n&nbsp;&nbsp;&nbsp;&nbsp;driver: local\n\n&nbsp;&nbsp;kafka_logs:\n\n&nbsp;&nbsp;&nbsp;&nbsp;driver: local\n\n&nbsp;&nbsp;zookeeper_data:\n\n&nbsp;&nbsp;&nbsp;&nbsp;driver: local\n\n&nbsp;&nbsp;zookeeper_log:\n\n&nbsp;&nbsp;&nbsp;&nbsp;driver: local<\/pre><p>This setup includes the following key components:<\/p><ul class=\"wp-block-list\">\n<li>Kafka container settings, such as the broker ID, listener configurations, and connection to ZooKeeper.&nbsp;<\/li>\n\n\n\n<li>ZooKeeper service settings, including the client port and tick time, for managing cluster coordination.&nbsp;<\/li>\n\n\n\n<li>Network configurations that allow Kafka and ZooKeeper containers to communicate using Docker&rsquo;s internal networking.&nbsp;<\/li>\n\n\n\n<li>Volume mappings for Kafka and ZooKeeper to ensure data is saved even if containers restart.&nbsp;<\/li>\n<\/ul><p>The result is a single-broker Kafka cluster with one ZooKeeper instance, which is ideal for development and testing. It uses the latest Confluent Community Platform images, a reliable and well-maintained distribution of Apache Kafka.<\/p><p>For detailed instructions on creating and managing additional Docker containers, including step-by-step commands and best practices, check out our comprehensive guide on <a href=\"\/tutorials\/docker-start-a-container\">creating Docker containers<\/a>.<\/p><figure data-wp-context='{\"imageId\":\"69e0031b43fe0\"}' data-wp-interactive=\"core\/image\" class=\"wp-block-image aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" width=\"2493\" height=\"1274\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/02\/4.png\/public\" alt=\"The Docker Compose file serves as the blueprint for your Kafka deployment, defining all necessary services and their configurations.\n\" class=\"wp-image-122537\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/02\/4.png\/w=2493,fit=scale-down 2493w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/02\/4.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/02\/4.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/02\/4.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/02\/4.png\/w=768,fit=scale-down 768w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/02\/4.png\/w=1536,fit=scale-down 1536w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/02\/4.png\/w=2048,fit=scale-down 2048w\" sizes=\"(max-width: 2493px) 100vw, 2493px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><h3 class=\"wp-block-heading\" id=\"h-4-start-kafka\">4. Start Kafka<\/h3><p>Launch your Kafka cluster using the Docker Compose command:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">docker compose up -d<\/pre><p>Verify that both services are running properly by checking the container status and logs:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">docker compose ps\n\ndocker compose logs kafka\n\ndocker compose logs zookeeper<\/pre><p>You should see both containers in the <strong>Up<\/strong> state with no error messages in the logs. The Kafka broker typically takes a few seconds to start up completely after ZooKeeper is ready.<\/p><figure data-wp-context='{\"imageId\":\"69e0031b447e9\"}' data-wp-interactive=\"core\/image\" class=\"wp-block-image aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" width=\"1943\" height=\"1155\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/02\/5.png\/public\" alt=\"You should see both containers in the &ldquo;Up&rdquo; state with no error messages in the logs.\n\" class=\"wp-image-122538\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/02\/5.png\/w=1943,fit=scale-down 1943w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/02\/5.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/02\/5.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/02\/5.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/02\/5.png\/w=768,fit=scale-down 768w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/02\/5.png\/w=1536,fit=scale-down 1536w\" sizes=\"(max-width: 1943px) 100vw, 1943px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><h3 class=\"wp-block-heading\" id=\"h-5-test-the-deployment\">5. Test the deployment<\/h3><p>Let&rsquo;s verify the deployment by creating a test topic and exchanging messages. First, create a new topic named <strong>test-topic<\/strong>:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">docker compose exec kafka kafka-topics --create --topic test-topic --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1<\/pre><p>Now, open two terminal windows to test message production and consumption. In the first terminal, start the console producer:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">docker compose exec kafka kafka-console-producer --topic test-topic --bootstrap-server localhost:9092<\/pre><p>In the second terminal, start the console consumer:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">docker compose exec kafka kafka-console-consumer --topic test-topic --bootstrap-server localhost:9092 --from-beginning<\/pre><p>Type some messages in the producer terminal and press Enter after each message. You should see these messages appearing in real-time in the consumer terminal, confirming that your Kafka deployment is working correctly. To exit either the producer or consumer, press Ctrl+C.<\/p><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69e0031b44fe6\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" width=\"2493\" height=\"1274\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/02\/6.png\/public\" alt=\"You should see these messages appearing in real-time in the consumer terminal.\" class=\"wp-image-122540\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/02\/6.png\/w=2493,fit=scale-down 2493w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/02\/6.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/02\/6.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/02\/6.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/02\/6.png\/w=768,fit=scale-down 768w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/02\/6.png\/w=1536,fit=scale-down 1536w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/02\/6.png\/w=2048,fit=scale-down 2048w\" sizes=\"(max-width: 2493px) 100vw, 2493px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><h3 class=\"wp-block-heading\" id=\"h-6-optimize-your-apache-kafka-deployment\">6. Optimize your Apache Kafka deployment<\/h3><p>Optimizing your Kafka deployment is key to ensuring strong performance and reliability. Here are some approaches you can use:<\/p><p><strong>Environment Variables Configuration<\/strong><\/p><p>Customize your Kafka setup using environment variables. Prefix Kafka properties with <strong>KAFKA_<\/strong>, convert them to uppercase and replace dots with underscores.<\/p><p>For example, use <strong>KAFKA_BROKER_ID<\/strong> and <strong>KAFKA_ZOOKEEPER_CONNECT<\/strong> to set basic broker settings. This method makes it easier to manage different configurations without editing core files.<\/p><p><strong>Scaling Kafka Brokers<\/strong><\/p><p>To scale your Kafka cluster with Docker Compose, you can adjust the number of broker instances. The command docker compose up &ndash;scale kafka=n works, but defining separate broker services in your <strong>docker-compose.yml<\/strong> file is a better option. This avoids broker ID conflicts and ensures smooth cluster coordination while giving you more control over configurations and resource allocation.<\/p><p><strong>External Access Configuration<\/strong><\/p><p>If you need to expose Kafka to external applications, set the <strong>KAFKA_ADVERTISED_LISTENERS<\/strong> property properly to maintain connectivity. For production, use node ports or load balancers for secure and reliable external access.<\/p><p>To maintain optimal performance, pay attention to hardware and configurations. Use high-speed SSDs for storage, manage partitions effectively, and set appropriate replication factors. Regularly monitor system metrics and tweak configurations based on your workload and use case.<\/p><p>For production environments, prioritize security with TLS encryption and MFA. Tools like <strong>Prometheus<\/strong> and <strong>Grafana<\/strong> can help monitor cluster health and performance, enabling you to identify and resolve bottlenecks before they become issues.<\/p><h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2><p>Deploying Apache Kafka with Docker offers an easy and efficient way to set up a powerful event-streaming platform. This guide walks you through the key steps, from preparing your Hostinger VPS to setting up a Docker Compose file that manages both Kafka and ZooKeeper.<\/p><p>But setting up Kafka is just the beginning. You can see its real potential only if it&rsquo;s part of a larger data ecosystem.<\/p><p>Keep in mind that while this guide is great for development and testing, production setups require extra steps for security, monitoring, and high availability. As your needs grow, you can scale your Kafka cluster by adding brokers, managing partitions effectively, and optimizing for specific workloads.<\/p><h2 class=\"wp-block-heading\" id=\"h-how-to-deploy-kafka-faq\">How to deploy Kafka FAQ<\/h2><div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1739263424720\"><h3 class=\"schema-faq-question\">What are the system requirements to deploy Kafka?<\/h3> <p class=\"schema-faq-answer\">A production Kafka deployment requires a minimum of <strong>4GB RAM<\/strong> (16GB recommended), <strong>2 CPU<\/strong> cores, and <strong>500GB<\/strong> storage, preferably on SSDs. Network requirements include 1-10GbE connectivity.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1739263430093\"><h3 class=\"schema-faq-question\">Can I run Kafka without Zookeeper in Docker?<\/h3> <p class=\"schema-faq-answer\">Yes, since Kafka 3.3, you can run Kafka without Zookeeper using KRaft mode. KRaft is production-ready for new clusters and simplifies deployment by eliminating the need for separate Zookeeper management.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1739263436040\"><h3 class=\"schema-faq-question\">How do I connect Kafka to external clients?<\/h3> <p class=\"schema-faq-answer\">External client access requires proper listener configuration. Use node ports, loadbalancers, or ingress controllers to expose Kafka outside the cluster. Clients must be able to connect to all brokers, typically through a load balancer that serves as the bootstrap endpoint.<\/p> <\/div> <\/div>\n","protected":false},"excerpt":{"rendered":"<p>Apache Kafka is an open-source messaging system that can process, store, and move data quickly. Companies often use it to [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/tutorials\/how-to-deploy-kafka-on-docker\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":481,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"How to deploy Apache Kafka on Docker","rank_math_description":"Check out this article to learn how to deploy Kafka on Docker with this guide. It will help you easily set up, test, and optimize your Kafka deployment.","rank_math_focus_keyword":"deploy kafka","footnotes":""},"categories":[22645,22644],"tags":[],"class_list":["post-122532","post","type-post","status-publish","format-standard","hentry","category-vps-use-cases","category-vps"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/how-to-deploy-kafka-on-docker","default":0},{"locale":"en-UK","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/how-to-deploy-kafka-on-docker","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/how-to-deploy-kafka-on-docker","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/how-to-deploy-kafka-on-docker","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/how-to-deploy-kafka-on-docker","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/how-to-deploy-kafka-on-docker","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/how-to-deploy-kafka-on-docker","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/how-to-deploy-kafka-on-docker","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/posts\/122532","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/users\/481"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/comments?post=122532"}],"version-history":[{"count":5,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/posts\/122532\/revisions"}],"predecessor-version":[{"id":123393,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/posts\/122532\/revisions\/123393"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/media?parent=122532"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/categories?post=122532"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/tags?post=122532"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}