PostHog Docker Deployment¶
This is a Docker Compose setup for running PostHog locally with environment variable configuration.
Overview¶
PostHog is an open-source product analytics platform. This setup includes: - PostgreSQL (database) - Redis (caching) - ClickHouse (analytics database) - Kafka (event streaming) - Zookeeper (Kafka coordination) - PostHog Web Server - PostHog Worker (background jobs) - PostHog Plugins Server
Environment Configuration¶
All configuration has been abstracted into environment variables for easier management and deployment across different environments.
Files¶
.env- Contains all environment variables (DO NOT commit to version control).env.example- Template file with default values (safe to commit)docker-compose.yml- Docker Compose configuration using environment variables.gitignore- Ensures.envand data directories are not committed
Environment Variables¶
The following categories of variables are configured:
Database¶
POSTGRES_USER- PostgreSQL usernamePOSTGRES_DB- PostgreSQL database namePOSTGRES_PASSWORD- PostgreSQL passwordDATABASE_URL- Full PostgreSQL connection string
ClickHouse¶
CLICKHOUSE_HOST- ClickHouse server hostnameCLICKHOUSE_DATABASE- ClickHouse database nameCLICKHOUSE_USER- ClickHouse usernameCLICKHOUSE_PASSWORD- ClickHouse passwordCLICKHOUSE_SECURE- Use TLS connection (true/false)CLICKHOUSE_VERIFY- Verify TLS certificates (true/false)
Redis¶
REDIS_URL- Redis connection URLREDIS_MAX_MEMORY- Maximum memory allocation for Redis
Kafka & Zookeeper¶
KAFKA_BROKER_ID- Kafka broker IDKAFKA_ZOOKEEPER_CONNECT- Zookeeper connection stringKAFKA_ADVERTISED_LISTENERS- Kafka advertised listenersKAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR- Replication factorKAFKA_TRANSACTION_STATE_LOG_MIN_ISR- Min in-sync replicasKAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR- Replication factorKAFKA_HOSTS- Kafka hosts for PostHogZOOKEEPER_CLIENT_PORT- Zookeeper client portZOOKEEPER_TICK_TIME- Zookeeper tick time
PostHog Application¶
SECRET_KEY- Django secret keySITE_URL- Public URL for PostHogWEB_PORT- Port to expose web interface (default: 8080)IS_BEHIND_PROXY- Whether behind a proxyDISABLE_SECURE_SSL_REDIRECT- Disable SSL redirectTRUST_ALL_PROXIES- Trust all proxy headers
Plugin Server¶
ENCRYPTION_KEYS- Encryption keys for pluginsENCRYPTION_SALT_KEYS- Salt keys for encryption
Getting Started¶
Prerequisites¶
- Docker and Docker Compose installed
- At least 4GB of available RAM
Setup¶
-
Copy the example environment file:
-
Customize the
.envfile: Edit.envand update values as needed: - Change passwords for production use
- Update
SECRET_KEY(generate a new one) - Update
SITE_URLif not using localhost -
Update
WEB_PORTif port 8080 is in use -
Generate secure keys:
Running PostHog¶
-
Start all services:
-
Check status:
-
View logs:
-
Access PostHog: Open your browser to:
http://localhost:8080(or your configuredSITE_URL)
Stopping PostHog¶
# Stop services but keep data
docker-compose stop
# Stop and remove containers (keeps data volumes)
docker-compose down
# Stop, remove containers AND delete all data
docker-compose down -v
Validation¶
After starting the services, you can verify the deployment:
Configuration Validation¶
Before deploying, validate your configuration:
This will show the resolved configuration with all environment variables substituted.
Troubleshooting¶
Services not starting¶
Check logs for specific service:
Service names: db, redis, clickhouse, kafka, zookeeper, worker, web, plugins
Connection issues¶
-
Ensure all services are running:
-
Check network connectivity:
Database migration issues¶
View web service logs to see migration progress:
Port conflicts¶
If port 8080 is in use, update WEB_PORT in .env:
Then restart:
Data Persistence¶
Data is persisted in Docker volumes:
- posthog_postgres-data - PostgreSQL data
- posthog_clickhouse-data - ClickHouse data
- posthog_zookeeper-data - Zookeeper data
- posthog_zookeeper-logs - Zookeeper logs
To backup data:
docker run --rm -v posthog_postgres-data:/data -v $(pwd):/backup alpine tar czf /backup/postgres-backup.tar.gz -C /data .
Security Notes¶
⚠️ Important for Production:
- Change all default passwords in
.env - Generate new
SECRET_KEYandENCRYPTION_KEYS - Never commit
.envfile to version control - Use proper SSL/TLS certificates
- Set
CLICKHOUSE_SECURE=trueandCLICKHOUSE_VERIFY=truefor production - Review and harden ClickHouse configuration
- Use a proper reverse proxy (nginx, Caddy, Traefik)
Development vs Production¶
This setup is optimized for development. For production:
- Use managed databases (RDS, Cloud SQL, etc.)
- Use managed Kafka (MSK, Confluent Cloud, etc.)
- Enable SSL/TLS for all connections
- Use proper secret management (AWS Secrets Manager, HashiCorp Vault, etc.)
- Set up monitoring and alerting
- Configure proper backups
- Review PostHog's official production deployment guides
Resources¶
License¶
This configuration follows PostHog's MIT license.