# How to start Kafka using Docker

*Run Kafka on any operating system in five minutes*

Docker provides the most portable way to run Kafka. It works identically on Mac, Windows, and Linux, and makes switching Kafka versions straightforward.

**What you'll learn:**
- How to run Kafka with Docker Compose
- How to execute Kafka commands against a Docker cluster
- How to manage your Docker-based Kafka environment

## Install Docker

| Platform | Installation |
|----------|--------------|
| Mac | [Docker Desktop for Mac](https://docs.docker.com/desktop/mac/install/) |
| Windows | [Docker Desktop for Windows](https://docs.docker.com/desktop/windows/install/) |
| Linux | [Docker Engine](https://docs.docker.com/engine/install/ubuntu/) (choose your distro) |

> Docker Desktop on Mac and Windows includes Docker Compose. On Linux, [install Docker Compose separately](https://docs.docker.com/compose/install/#install-compose).

## Run Kafka with Docker Compose

Docker Compose runs multi-container applications. Each Kafka component (ZooKeeper, broker) runs in a separate container.

**Step 1: Clone the repository**

```bash
git clone https://github.com/conduktor/kafka-stack-docker-compose.git
cd kafka-stack-docker-compose
```

**Step 2: Choose a configuration**

| File | Configuration |
|------|---------------|
| `zk-single-kafka-single.yml` | One ZooKeeper, one broker (learning) |
| `zk-single-kafka-multiple.yml` | One ZooKeeper, multiple brokers |
| `zk-multiple-kafka-multiple.yml` | Multiple ZooKeeper, multiple brokers |

**Step 3: Start the cluster**

```bash
docker-compose -f zk-single-kafka-single.yml up -d
```

**Step 4: Verify the cluster**

```bash
docker-compose -f zk-single-kafka-single.yml ps
```

Expected output:
```
 Name             Command            State                       Ports
-------------------------------------------------------------------------------------------
kafka1   /etc/confluent/docker/run   Up      0.0.0.0:9092->9092/tcp, 0.0.0.0:9999->9999/tcp
zoo1     /etc/confluent/docker/run   Up      0.0.0.0:2181->2181/tcp, 2888/tcp, 3888/tcp
```

Kafka is available at `localhost:9092`.

## Run Kafka commands

You have two options for running Kafka CLI commands:

### Option 1: Run inside the container

```bash
docker exec -it kafka1 /bin/bash
```

Inside the container, run commands without the `.sh` extension:

```bash
kafka-topics --version
```

### Option 2: Run from your host machine

Install the Kafka binaries on your system (skip the steps for starting ZooKeeper and Kafka):

- [Mac](https://www.conduktor.io/kafka/how-to-install-apache-kafka-on-mac) (follow the whole document except starting Kafka and ZooKeeper)
- [Linux](https://www.conduktor.io/kafka/how-to-install-apache-kafka-on-linux) (follow the whole document except starting Kafka and ZooKeeper)
- [Windows](https://www.conduktor.io/kafka/how-to-install-apache-kafka-on-windows) (follow the whole document except starting Kafka and ZooKeeper)

Then run commands with the `.sh` extension:

```bash
kafka-topics.sh --bootstrap-server localhost:9092 --list
```

## Stop and clean up

**Stop containers** (preserves data):
```bash
docker-compose -f zk-single-kafka-single.yml stop
```

**Remove containers and network** (removes data):
```bash
docker-compose -f zk-single-kafka-single.yml down
```

> **See it in practice with Conduktor**
> [Conduktor Console](https://docs.conduktor.io/guide/conduktor-in-production/admin/configure-clusters) can connect to your Docker-based Kafka cluster at `localhost:9092` for visual management of topics and messages.

## Next steps

- [CLI tutorials](https://www.conduktor.io/kafka/kafka-cli-tutorial) to practice Kafka commands against your cluster
- [Topics CLI tutorial](https://www.conduktor.io/kafka/kafka-topics-cli-tutorial) to create and manage your first topics
- [Kafka fundamentals](https://www.conduktor.io/kafka/kafka-fundamentals) to understand core concepts
