Title: Running Kafka Docker Container Project on WSL System: A Comprehensive Guide
Introduction
In this article, we will guide you through the process of running a Kafka Docker container project on a WSL (Windows Subsystem for Linux) system. We will cover the necessary steps, key concepts, and provide detailed explanations to help you successfully run your project.
Prerequisites
Before we begin, ensure you have the following prerequisites installed:
- Windows 10 with the latest updates
- WSL (Windows Subsystem for Linux)
- Docker Desktop for Windows
Installing Docker on WSL
Follow these steps to install Docker on your WSL system:
-
Open the terminal in your WSL distribution (e.g., Ubuntu).
-
Run the following command to install Docker:
sudo apt-get update sudo apt-get install docker.io -
To start the Docker service, use:
sudo systemctl start dockerAnd to ensure it starts on boot, use:
sudo systemctl enable docker
Running Kafka Docker Container
Now, let's run a Kafka Docker container:
-
Pull the official Confluent Docker image:
docker pull confluentinc/cp-kafka -
Run the Kafka container with the following command:
docker run -d --rm --name my-kafka -p 9092:9092 -p 9093:9093 confluentinc/cp-kafkaThis command starts the Kafka container in detached mode, with the name
my-kafka. The container exposes ports 9092 (for Kafka) and 9093 (for Zookeeper).
Producer and Consumer Examples
Here are examples of producing and consuming messages using the Kafka Docker container:
Producer:
docker run -it --rm --name my-kafka-producer confluentinc/cp-kafka kafka-console-producer --broker-list localhost:9092 --topic my-topic
Consumer:
docker run -it --rm --name my-kafka-consumer confluentinc/cp-kafka kafka-console-consumer --bootstrap-server localhost:9092 --topic my-topic --from-beginning
Troubleshooting
If you encounter issues related to virtualization, ensure that your system supports it. Docker for WSL uses the Windows kernel for container execution, which does not rely on virtualization.
Summary
In this article, we covered the steps to run a Kafka Docker container project on a WSL system. We discussed the prerequisites, installation of Docker, and running a Kafka container. Additionally, we provided examples of producing and consuming messages using the container.