Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

Self-Hosting n8n with Docker Compose: Five Settings to Get Right on Day One

Description and use

Configuring n8n in Docker Compose with PostgreSQL, a fixed encryption key, a public URL, execution pruning, and the correct timezone ensures reliable operation and simplifies backups.

Problem

Running n8n in Docker is quick, but maintaining credentials, webhooks, disk space, and backups over time requires additional configuration that the quick‑start omits.

Outcome

The configured instance runs reliably for years, preserving credentials, handling concurrent webhooks, preventing disk exhaustion, and aligning schedules with the desired timezone.

Workflow

  • Create a docker‑compose.yml with postgres and n8n services
  • Add .env file with PG_PASSWORD and N8N_ENCRYPTION_KEY
  • Set environment variables: DB_TYPE, DB_POSTGRESDB_HOST, DB_POSTGRESDB_DATABASE, DB_POSTGRESDB_USER, DB_POSTGRESDB_PASSWORD, N8N_ENCRYPTION_KEY, N8N_HOST, N8N_PROTOCOL, WEBHOOK_URL, GENERIC_TIMEZONE, EXECUTIONS_DATA_PRUNE, EXECUTIONS_DATA_MAX_AGE
  • Bind n8n port to 127.0.0.1:5678
  • Run docker compose up -d
  • Schedule nightly pg_dump and .env backup
  • Update with docker compose pull && docker compose up -d after reviewing release notes

Evidence

n8n encrypts every saved credential with N8N_ENCRYPTION_KEY. If you don't set one, it generates a key inside the data volume. Rebuild the container without that volume and every credential becomes unreadable.

Source

SQLite is fine for a test. Once you have busy webhooks and thousands of executions, Postgres handles concurrent writes better and is far easier to back up with pg_dump.

Source

Behind a reverse proxy, n8n doesn't know its own address, so webhook nodes show localhost:5678 URLs that nothing outside can reach. WEBHOOK_URL fixes that.

Source

Every run is stored with its input and output data. Without pruning, the database grows until the disk fills. EXECUTIONS_DATA_MAX_AGE: 168 keeps one week of history; raise it if you need longer audits.

Source

Schedule Trigger nodes use GENERIC_TIMEZONE. Leave it unset and your "9 AM" workflow runs at 9 AM UTC, which is 2:30 PM in India.

Source

  • Record date: 2026-10-21T06:41:12.468Z