Skip to content

Instantly share code, notes, and snippets.

@yannick
Created March 19, 2026 11:46
Show Gist options
  • Select an option

  • Save yannick/50a20d6eb644e8e1c1cc50c119b94914 to your computer and use it in GitHub Desktop.

Select an option

Save yannick/50a20d6eb644e8e1c1cc50c119b94914 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Start/stop a local Redpanda instance for development using Apple container CLI
#pre setup you need to do:
# sudo container system property set dns.domain rp
# sudo container system property set dns.domain rp
# gh auth token | container registry login ghcr.io -u $(gh api user | jq .login -r) --password-stdin
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
CONTAINER_NAME="redpanda-dev"
REDPANDA_IMAGE="docker.redpanda.com/redpandadata/redpanda:latest"
KAFKA_PORT=19092
ADMIN_PORT=19644
ADMIN_UI_PORT=8888
DOMAIN=rp
usage() {
echo "Usage: $0 start|stop"
exit 1
}
ensure_container_cli() {
if ! command -v container &> /dev/null; then
echo "Error: 'container' CLI is required but not installed"
echo "Install with: brew install container"
exit 1
fi
}
ensure_runtime() {
if ! container system info &> /dev/null 2>&1; then
echo "Starting container runtime..."
container system start
# Give the runtime a moment to initialize
sleep 2
fi
}
do_start() {
ensure_container_cli
ensure_runtime
container system property set dns.domain rp
# Remove any existing container
echo "Removing existing $CONTAINER_NAME container (if any)..."
container rm -f "$CONTAINER_NAME" 2>/dev/null || true
echo "Starting Redpanda container..."
container run -d --name "$CONTAINER_NAME" \
--memory 1512M \
--dns-domain ${DOMAIN} \
-p ${KAFKA_PORT}:${KAFKA_PORT} \
-p ${ADMIN_PORT}:9644 \
"$REDPANDA_IMAGE" \
redpanda start \
--kafka-addr internal://[::]:9092,external://[::]:${KAFKA_PORT} \
--advertise-kafka-addr internal://${CONTAINER_NAME}.${DOMAIN}:9092,external://${CONTAINER_NAME}.${DOMAIN}:${KAFKA_PORT} \
--smp 2 \
--memory 512M \
--mode dev-container \
--default-log-level=warn
echo ""
container run -d --name redpanda-console \
-p ${ADMIN_UI_PORT}:8080 \
--dns-domain ${DOMAIN} \
-e KAFKA_BROKERS=${CONTAINER_NAME}.${DOMAIN}:${KAFKA_PORT} \
redpandadata/console:latest
echo "Waiting for Redpanda to be healthy..."
max_attempts=30
attempt=0
while [ $attempt -lt $max_attempts ]; do
if container exec "$CONTAINER_NAME" rpk cluster health 2>/dev/null | grep -q "Healthy:.*true"; then
break
fi
attempt=$((attempt + 1))
sleep 1
done
if [ $attempt -eq $max_attempts ]; then
echo "Warning: Redpanda health check timed out after ${max_attempts}s, but cluster may still be starting"
else
echo "Redpanda is healthy!"
fi
echo ""
echo "Redpanda is running!"
echo ""
echo "Kafka broker: localhost:${KAFKA_PORT}"
echo "Admin API: http://localhost:${ADMIN_PORT}"
echo "Console UI: http://localhost:${ADMIN_UI_PORT}"
echo ""
echo "try with: echo bar | kcat -P -b redpanda-dev.rp:19092 -t foo; kcat -C -b redpanda-dev.rp:19092 -t foo -o -1 -c 1"
echo ""
echo "To stop: $0 stop"
}
do_stop() {
ensure_container_cli
echo "Stopping $CONTAINER_NAME..."
container stop "$CONTAINER_NAME" 2>/dev/null || true
container rm -f "$CONTAINER_NAME" 2>/dev/null || true
echo "Stopping redpanda-console..."
container stop "redpanda-console" 2>/dev/null || true
container rm -f "redpanda-console" 2>/dev/null || true
echo "Redpanda stopped and removed."
}
case "${1:-}" in
start) do_start ;;
stop) do_stop ;;
*) usage ;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment