Docker로 로컬 Kafka 설정
Docker Compose를 사용하여 로컬 Kafka 클러스터를 빠르게 설정하고 개발과 테스트를 위한 샌드박스를 구축하는 방법을 배웁니다.
Docker로 로컬 Kafka 설정은(는) CoddyKit의 무료 Advanced Spring Boot 4: Event-Driven Architecture (Kafka) 강의입니다. 이것은 4개 중 3번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Advanced Spring Boot 4: Event-Driven Architecture (Kafka) 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Advanced Spring Boot 4: Event-Driven Architecture (Kafka) 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
Local Kafka: Your Dev Sandbox
When building applications that use Apache Kafka, you'll need a Kafka cluster to connect to. For development and testing, setting up a local cluster is ideal.
It provides a safe, isolated environment where you can experiment without affecting production systems. This lesson will guide you through setting it up easily with Docker.
Docker and Docker Compose Basics
Docker is a platform for developing, shipping, and running applications in containers. Containers are lightweight, portable, and self-sufficient units.
Docker Compose is a tool for defining and running multi-container Docker applications. You use a YAML file to configure your application's services, then create and start them all with a single command.
Essential Kafka Local Components
A minimal Kafka cluster requires two main components to function:
- Zookeeper: This service manages Kafka brokers, handling leader election, configuration, and coordination. Kafka relies on Zookeeper for its operational state.
- Kafka Broker: This is the core server that stores topics, handles message production and consumption, and replicates data. You'll typically run at least one broker.
Defining Your Services with YAML
We'll define our Kafka setup using a docker-compose.yml file. This file tells Docker Compose which services to run, which images to use, and how they should be configured and networked.
Each service in the file represents a container that will be launched. Let's start building it step-by-step.
Zookeeper in Docker Compose
First, let's define the Zookeeper service. We'll use a standard Zookeeper image and expose its default client port.
version: '3.8'
services:
zookeeper:
image: confluentinc/cp-zookeeper:7.5.0
container_name: zookeeper
ports:
- "2181:2181"
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000Here, ports: "2181:2181" maps the container's port 2181 to your host's port 2181.
Kafka Broker in Docker Compose
Next, we add the Kafka broker service. It needs to know how to connect to Zookeeper and also exposes its own ports for clients.
kafka:
image: confluentinc/cp-kafka:7.5.0
container_name: kafka
ports:
- "9092:9092"
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
depends_on:
- zookeeperdepends_on: zookeeper ensures Zookeeper starts before Kafka.
Your Complete Kafka Setup File
Combining both services, your docker-compose.yml file looks like this:
version: '3.8'
services:
zookeeper:
image: confluentinc/cp-zookeeper:7.5.0
container_name: zookeeper
ports:
- "2181:2181"
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
kafka:
image: confluentinc/cp-kafka:7.5.0
container_name: kafka
ports:
- "9092:9092"
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
depends_on:
- zookeeperSave this content into a file named docker-compose.yml in an empty directory.
Launching Your Kafka Cluster
Once your docker-compose.yml file is ready, navigate to its directory in your terminal. Then, use the following command to start your Kafka cluster:
docker-compose up -dup: Builds, (re)creates, starts, and attaches to containers for a service.-d: Runs containers in detached mode (in the background).
Docker will download images (if not present) and start Zookeeper, then Kafka.
Confirming Kafka is Running
After running docker-compose up -d, you can check if your services are running correctly:
docker ps: Lists all running Docker containers. You should seezookeeperandkafka.docker logs kafka: Shows the logs for the Kafka container. Look for messages indicating it started successfully, like "started (kafka.server.KafkaServer)".
To stop and remove the containers, use docker-compose down.
Docker Compose Command Check
You've just created a docker-compose.yml file and want to start your Kafka cluster in the background. Which command should you use?
Recap: Local Kafka with Docker
Congratulations! You've learned how to set up a local Kafka cluster using Docker Compose. Here's a quick summary:
- Local Kafka provides an isolated dev environment.
- Docker Compose uses a
docker-compose.ymlfile to define multi-container apps. - A minimal Kafka setup requires Zookeeper and a Kafka Broker.
- The
docker-compose.ymlspecifies images, ports, and environment variables. - Use
docker-compose up -dto start anddocker-compose downto stop your cluster.
Now you have a sandbox to build your Spring Boot Kafka applications!
자주 묻는 질문
“Docker로 로컬 Kafka 설정” 강의는 무료인가요?
네 — “Docker로 로컬 Kafka 설정” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Advanced Spring Boot 4: Event-Driven Architecture (Kafka) 강의 전체를 잠금 해제할 수 있습니다. Advanced Spring Boot 4: Event-Driven Architecture (Kafka) 강의에는 총 4개의 강의가 포함되어 있습니다.
“Docker로 로컬 Kafka 설정”에서 뭘 배우나요?
Docker Compose를 사용하여 로컬 Kafka 클러스터를 빠르게 설정하고 개발과 테스트를 위한 샌드박스를 구축하는 방법을 배웁니다. 브라우저에서 직접 실행하는 실습 코드로 Advanced Spring Boot 4: Event-Driven Architecture (Kafka)을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
Advanced Spring Boot 4: Event-Driven Architecture (Kafka)을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 Advanced Spring Boot 4: Event-Driven Architecture (Kafka)은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 3번째 강의입니다.
“Docker로 로컬 Kafka 설정” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Advanced Spring Boot 4: Event-Driven Architecture (Kafka) 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Advanced Spring Boot 4: Event-Driven Architecture (Kafka) 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- Kafka 아키텍처 개요
- 토픽, 파티션, 오프셋
- Docker로 로컬 Kafka 설정
- 소비자 그룹과 재조정