Skip to main content

ETCD

ETCD is a distributed key-value store that provides a reliable way to store data across a cluster of machines. It is often used for configuration management, service discovery, and coordination of distributed systems.

Architecture

This container provides a production-ready ETCD setup with:

  • Go 1.24.12 compiled from source
  • ETCD 3.6.7 with v3 API
  • Multi-stage build for minimal runtime image (debian:bookworm-slim)
  • Environment-driven configuration for all settings
  • TLS support for secure communication
  • Automatic data directory creation with proper permissions (700)

Quick Start

services:
etcd:
image: ghcr.io/supanadit/containers/etcd:3.6.7-r4
container_name: etcd
environment:
ETCD_NAME: etcd0
ETCD_ADVERTISE_CLIENT_URLS: http://etcd:2379
ETCD_INITIAL_CLUSTER: etcd0=http://etcd:2380
ETCD_INITIAL_CLUSTER_STATE: new
ETCD_INITIAL_CLUSTER_TOKEN: etcd-cluster
ports:
- "2379:2379"
- "2380:2380"
volumes:
- etcd_data:/var/lib/etcd
healthcheck:
test: ["CMD", "etcdctl", "--endpoints=127.0.0.1:2379", "endpoint", "health"]
interval: 5s
timeout: 3s
retries: 30

volumes:
etcd_data:

Built-in Settings

The following settings are hardcoded in the entrypoint for optimal performance:

SettingValueDescription
--heartbeat-interval1000Heartbeat interval in milliseconds
--election-timeout5000Election timeout in milliseconds
--snapshot-count5000Number of operations before snapshot
--auto-compaction-retention1Auto compaction retention in hours
--max-request-bytes10485760Maximum request size (10MB)

Deployment Scenarios

ScenarioUse CaseDocumentation
Single NodeDevelopment/testingBasic single node
3-Node ClusterProductionMulti-node cluster
TLS SecuredProduction with securityTLS authentication

Common Operations

# Set a key
docker compose exec etcd etcdctl put mykey "myvalue"

# Get a key
docker compose exec etcd etcdctl get mykey

# List all keys
docker compose exec etcd etcdctl get / --prefix --keys-only

# Check cluster health
docker compose exec etcd etcdctl endpoint health

# Check cluster status
docker compose exec etcd etcdctl endpoint status

Environment Variables

VariableDescriptionDefault
ETCD_NAMENode nameetcd-node
ETCD_DATA_DIRData directory/var/lib/etcd
ETCD_LISTEN_PEER_URLSPeer listening URLshttp://0.0.0.0:2380
ETCD_LISTEN_CLIENT_URLSClient listening URLshttp://0.0.0.0:2379
ETCD_ADVERTISE_CLIENT_URLSAdvertised client URLsAuto-detected from container IP
ETCD_INITIAL_ADVERTISE_PEER_URLSAdvertised peer URLsAuto-detected from container IP
ETCD_INITIAL_CLUSTERInitial cluster configurationAuto-generated from name and IP
ETCD_INITIAL_CLUSTER_STATEInitial cluster statenew
ETCD_INITIAL_CLUSTER_TOKENCluster tokenetcd-cluster

TLS Environment Variables

VariableDescription
ETCD_CERT_FILETLS certificate file for client connections
ETCD_KEY_FILETLS key file for client connections
ETCD_CLIENT_CERT_AUTHEnable client certificate authentication (true/false)
ETCD_TRUSTED_CA_FILETrusted CA certificate file
ETCD_PEER_CERT_FILETLS certificate file for peer connections
ETCD_PEER_KEY_FILETLS key file for peer connections
ETCD_PEER_CLIENT_CERT_AUTHEnable peer certificate authentication (true/false)
ETCD_PEER_TRUSTED_CA_FILETrusted CA file for peers

Next Steps