PortGate

Blueprints · Docker & Databases

Production 15 min · Docker

Kafka on localhost

Publishes Kafka on 127.0.0.1. The controller port is not published on the host. This is a single-node broker.

Why this should not be public

A Kafka broker without SASL lets any client read and write every topic. The advertised listener also tells clients where to connect, so a wrong value leaks internal hostnames.

Live config

Baked-in protections

Step 1 · yaml

Compose file

/opt/kafka-loopback/compose.yaml

Written under the compose directory. It is not started. The image tag is the release this blueprint was checked with: look at the project's release notes and use the newest patched tag.

services:
  app:
    image: apache/kafka:3.8.0
    ports:
      - "127.0.0.1:9092:9092"
    environment:
      KAFKA_NODE_ID: "1"
      KAFKA_PROCESS_ROLES: broker,controller
      KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092,CONTROLLER://0.0.0.0:9093
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://127.0.0.1:9092
      KAFKA_CONTROLLER_LISTENER_NAMES: CONTROLLER
      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT
      KAFKA_CONTROLLER_QUORUM_VOTERS: [email protected]:9093
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: "1"
      KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: "1"
      KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: "1"
    security_opt:
      - no-new-privileges:true
    restart: unless-stopped

Step 2 · bash

Start script

/opt/kafka-loopback/up.sh

Review the image tag and the password, then run this yourself.

#!/bin/sh
set -eu
cd "/opt/kafka-loopback"
if grep -q 'change-me' compose.yaml; then
  echo "Replace change-me before starting."
  exit 1
fi
docker compose up -d

Step 3 · bash

Read-only check

/root/portgate-blueprints/kafka-loopback-check.sh

Prints status. It does not change the service.

#!/bin/sh
set -eu
if command -v docker >/dev/null 2>&1; then
  docker ps --format '{{.Names}} {{.Ports}}' || echo "Docker is installed but the daemon did not answer."
else
  echo "Docker is not installed. The compose file is staged only."
fi