A production-ready n8n setup using Docker Compose with Traefik reverse proxy, PostgreSQL database, and Let's Encrypt SSL certificates via Cloudflare DNS challenge.
- Automatic SSL certificates via Let's Encrypt (DNS-01 challenge with Cloudflare)
- Traefik reverse proxy with automatic HTTPS redirect
- PostgreSQL database for n8n workflows
- Docker Compose for easy deployment
- Production-ready configuration
- Docker and Docker Compose installed
- A domain name configured in Cloudflare
- Cloudflare API token with DNS edit permissions
-
Clone the repository
git clone git@github.com:sn1ce/docker-n8n.git cd docker-n8n -
Copy the example environment file
cp .env.example .env
-
Edit
.envwith your configurationnano .env
Required values:
N8N_HOST: Your n8n subdomain (e.g.,n8n.yourdomain.com)LETSENCRYPT_EMAIL: Your email for Let's Encrypt notificationsCF_DNS_API_TOKEN: Your Cloudflare API tokenPOSTGRES_PASSWORD: Strong password for PostgreSQLN8N_BASIC_AUTH_PASSWORD: Strong password for n8n access
-
Start the stack
docker compose up -d
-
Access n8n
- Navigate to
https://your-n8n-host.com - Login with the credentials from your
.envfile
- Navigate to
- Go to Cloudflare Dashboard
- Click "Create Token"
- Use the "Edit zone DNS" template
- Restrict to your specific domain zone
- Copy the token to your
.envfile
All configuration is done via the .env file. See .env.example for all available options.
Traefik is configured to:
- Automatically redirect HTTP to HTTPS
- Request SSL certificates via DNS-01 challenge
- Route traffic to the n8n container
PostgreSQL is used as the database backend for n8n, providing better performance and reliability than SQLite.
docker compose logs -fdocker compose restartdocker compose pull
docker compose up -ddocker compose exec postgres pg_dump -U n8n n8n > backup.sql- Never commit your
.envfile - Use strong passwords for all credentials
- Keep your Cloudflare API token secure
- Regularly update Docker images
- Consider enabling Traefik dashboard authentication if needed
- Check Traefik logs:
docker compose logs traefik - Verify Cloudflare API token has correct permissions
- Ensure DNS records are properly configured
- Verify PostgreSQL is healthy:
docker compose ps - Check database logs:
docker compose logs postgres
- Verify
N8N_HOSTmatches your domain - Check Traefik routing labels in
compose.yaml - Ensure ports 80 and 443 are open
MIT
Contributions are welcome! Please feel free to submit a Pull Request.