I self host a lot of software on one single server, jugling all this different software is super easy with docker compose and Traefik, Because of this I decided to share my setup for handling n8n with docker compose and Traefik here.
here’s the most important part:
services:
n8n:
image: n8nio/n8n
container_name: n8n
restart: unless-stopped
ports:
- "127.0.0.1:5678:5678" # Only exposed locally, Traefik handles external access
environment:
- DB_TYPE=postgresdb
- DB_POSTGRESDB_HOST=postgres
- DB_POSTGRESDB_PORT=5432
- DB_POSTGRESDB_DATABASE=${POSTGRES_DB} # Comes from .env file
- DB_POSTGRESDB_USER=${POSTGRES_USER} # Comes from .env file
- DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD} # Comes from .env file
- NODE_FUNCTION_ALLOW_EXTERNAL=langchain # Important for LangChain nodes!
volumes:
- n8n_data:/home/node/.n8n # Persist your workflows and settings
networks:
- n8n
- traefik
depends_on:
- postgres
labels: # Traefik magic happens here
- "traefik.enable=true"
- "traefik.http.routers.n8n.rule=Host(`n8n.yourdomain.com`)" # <<< REPLACE WITH YOUR DOMAIN!
- "traefik.http.routers.n8n.entrypoints=websecure"
- "traefik.http.routers.n8n.tls.certresolver=myresolver" # <<< REPLACE 'myresolver' with your Traefik resolver name!
- "traefik.http.services.n8n.loadbalancer.server.port=5678"
...
For a complete overview 0please consut my original article here: