Running n8n with Docker Compose in production

A production Compose stack for n8n needs PostgreSQL, persistent volumes, a protected encryption key, pinned images and planned restarts. This page explains each choice and what to confirm before go-live.

On this page

Running n8n with Docker Compose in production: when a single host is enough

A single host running Docker Compose is production-ready for n8n when four things are set correctly: PostgreSQL replaces the default SQLite database, the data directories sit on persistent volumes, the encryption key is generated once and stored safely, and every image is pinned to a specific tag rather than a moving one. If your team runs n8n on servers it controls and wants a small, auditable stack, this is a reasonable starting point. The stack typically contains the n8n main container, a PostgreSQL container with its own volume, and, where you enable them, the task runner and sandbox services that execute Code node logic outside the main process. Restart policies keep containers running after a host reboot, but they do not replace backups or monitoring, which you need to plan separately.

Confirm three things before you commit to one host. First, the n8n version you deploy and the PostgreSQL major version you choose must both be on current support lists, so check the n8n release notes and the PostgreSQL versioning policy at the time you build. Second, the encryption key is the single value that makes stored credentials readable, so losing it or changing it without a plan means re-entering credentials, and it must be written to a secrets store your team controls. Third, a single host is a single point of failure: one host failure stops triggers, webhooks and executions until you restore service elsewhere. Ask your team how long an outage can last before the business notices.

Plan to move beyond one host when execution volume, webhook traffic or uptime requirements outgrow what one machine can absorb. The move path is queue mode, in which the main instance handles triggers and webhooks, Redis carries executions to a pool of workers, and PostgreSQL holds workflow data. In queue mode the encryption key must be shared with every worker and webhook processor, so the key handling in your Compose files must be redesigned for multiple hosts or containers. High availability with several main instances is restricted to Enterprise self-hosted deployments, so if you need it, confirm the license terms with n8n before designing around it. Kubernetes or a managed cloud platform are alternatives when your organization already runs them and has staff to operate them.

Only the proxy faces users, and state sits on named volumes

The diagram starts at the reverse proxy, the only service that accepts traffic from users and webhook callers. It forwards requests to the n8n main container, which reads and writes workflow data in the PostgreSQL container and uses the encryption key to protect stored credentials. The task runner receives code work from main and hands it to a separate sandbox service. Check that only the proxy publishes a port and that both database and n8n data sit on persistent volumes.

Request path, trust boundary and persistent storage in the Compose stack.

Which Compose settings fit which situation

This table compares the main Compose choices for n8n: database, storage, image tagging and restart behavior. Read each row for the situation where the option fits and the trade-off you accept by choosing it. The main takeaway is that a single-container test setup and a production stack differ most in the database, the encryption key location and how you control upgrades.

SettingWhen it fitsTrade-off to accept
SQLite (default database)Local evaluation, a throwaway test instance or a single-user sandbox where losing the data is acceptableNot a production choice for a shared instance. Move to PostgreSQL before real workflows and credentials depend on it.
PostgreSQLAny production instance and any setup that may later use queue mode, since workers read and write workflow data in PostgreSQLYou run and back up a second service, and you must plan its own version support and upgrades.
Named volumesData directories for PostgreSQL and n8n files when Docker manages storage and you want the platform to handle permissionsData is harder to see and copy from the host, so backup steps must be written and tested with docker commands.
Bind mountsWhen you need files on a known host path for backup tooling, custom certificates or direct inspectionHost file ownership and permissions must match the container user, and paths become part of your server configuration.
Pinned image tagsProduction, where upgrades are reviewed, tested in staging and applied on a known releaseYou must watch release notes and move the tag yourself, so the pin needs an owner and a schedule.
Floating tags (for example latest)Disposable development or demo environments where picking up new releases automatically is the goalA pull or restart can change the running version without review, which can break workflows after a major change.
Restart policy set to unless-stoppedLong-running services where containers should come back after a host reboot unless an operator stopped them on purposeA crash loop can keep restarting a broken container, so alerting on container health is still needed.
Restart policy set to noMaintenance windows or one-off troubleshooting where you want containers to stay down until started manuallyNothing recovers after a reboot or crash, so this setting is unsuitable for a production service.

How to build the Compose stack step by step

This sequence takes a single Docker host from an empty directory to a running n8n stack backed by a supported PostgreSQL version, with the encryption key, data volumes, pinned images and restart behavior set before the first start. Each step ends with a check you can run before moving on.

  1. Choose a supported PostgreSQL major version

    Pick a PostgreSQL major version that is still inside its support window on the day you build the stack, and record the choice in your deployment notes. The DeployOpen team, or your own platform engineers, check the PostgreSQL versioning policy page and confirm the end-of-support dates for each major version. Pin the chosen major version (for example, the 17 or 18 tag) rather than a generic latest tag. Done when the version and its support end date are written in the change record and you can name the source you checked.

  2. Define the database and n8n services

    Create a docker-compose.yml file with two services: a postgres service using the pinned PostgreSQL image, and an n8n service that sets DB_TYPE=postgresdb and the connection keys (host, port, database, user and password). Use an environment file for secrets so they stay out of the Compose file itself. Do not leave n8n on its default SQLite storage for production. Done when docker compose config renders both services without errors and shows the database settings you intended.

  3. Store the encryption key outside the image

    Generate a strong N8N_ENCRYPTION_KEY value and place it in a secrets file on the host with restricted file permissions, not in the Compose file or the image. Keep a copy in your organization's secrets vault, because losing this key means stored credentials cannot be decrypted. If you later add queue mode workers, every worker and webhook processor must receive the same key. Done when the key is loaded from the external file, the file is readable only by the account that runs Compose, and the backup location is confirmed by a second person.

  4. Mount persistent volumes for data

    Declare named volumes or bind mounts for the PostgreSQL data directory and the n8n data directory (/home/node/.n8n), so workflows, settings and binary data survive container replacement. Confirm the path your n8n image version uses for its data directory in the official documentation before mounting. Keep database files on storage that your backup tooling can reach. Done when you run docker volume ls or list the bind-mount paths, and both appear with the expected names before any data is written.

  5. Pin image tags and set restart policies

    Replace every latest tag with an exact n8n and PostgreSQL image version, and set restart: unless-stopped on both services so they return after a host reboot or a container crash. n8n publishes semantic versions with frequent minor releases, so a pinned tag is what keeps upgrades a planned change. Record the exact tags in version control next to the Compose file. Done when docker compose images lists fixed tags for both services and docker inspect shows the restart policy as configured.

  6. Add the task runner and sandbox services

    If your n8n version runs Code node tasks in a separate task runner, add the runner service the official documentation describes for that version, with the same pinned image family, the shared runner authentication token and a network path to the n8n service. Keep the runner off any public network. Confirm for your chosen version whether the runner runs as a sidecar container or a separate service, and whether a sandbox is required for JavaScript or Python code. Done when the runner container reports a connection to n8n in its logs and a test Code node runs successfully.

  7. Start the stack and verify it

    Run docker compose up -d, then check that PostgreSQL accepts connections and that n8n finishes its database migrations without errors. Open the n8n editor through your internal address, create a test workflow with one Code node, save it, and run it once. Restart the host or run docker compose restart and confirm the workflow and the test credential still work, which proves the volumes and encryption key are persisting correctly. Done when the logs show no migration or decryption errors and the workflow survives the restart.

How to protect the encryption key and database credentials

The encryption key and the database password together decide whether a copy of your n8n data is useful to someone else. The cards below cover the failure modes that matter most in a Compose stack: losing the key, sharing it badly, and leaving credentials in plain files or environment variables.

Losing the encryption key

n8n encrypts stored credentials with a key generated on first start, and the key lives in the instance's configuration. If the container volume is rebuilt without that key, saved credentials in PostgreSQL cannot be decrypted and every workflow that depends on them fails. Store a copy of the key in your secrets manager outside the Compose host, and test a restore from backup to confirm the key matches the database dump.

Queue mode docs

Sharing the key with workers

In queue mode, the main instance's encryption key must be present on every worker and webhook processor, or those processes cannot read credentials from the database. Each worker container needs the same value, delivered the same way as the main instance. Check that no worker was started with a freshly generated key, because the mismatch appears only when a workflow using a credential runs on that worker.

Queue mode docs

Key in plain Compose files

Putting the key or database password directly in docker-compose.yml places it in version control, shell history and docker inspect output for anyone with host access. Move values into an .env file or Docker secrets with restricted file permissions, keep the file out of Git, and confirm that .env is excluded in your repository ignore rules.

Weak database credentials

The PostgreSQL user that n8n connects with should own only the database it needs, not act as a superuser. Generate a long random password, rotate it through a planned change that updates both the database and the Compose secret, and confirm that the PostgreSQL service is not published on a host port that other machines can reach.

Authentication methods

Credentials exposed through logs and backups

Backups of the PostgreSQL volume contain encrypted credentials, but a backup that also contains the key, or a log that echoes environment variables, gives an attacker everything needed. Store the key and database dumps in separate locations with different access, and review startup logs and support bundles for printed secrets before sharing them.

No key ownership or rotation plan

Nobody may own the encryption key, so it is never rotated and nobody knows where it is kept when a new engineer takes over. Name an owner, record where each copy lives, and write a short procedure for replacing the database password and reissuing the key to workers. Review the procedure whenever the Compose stack changes.

Which PostgreSQL version to run and how it gets upgraded

Pick a PostgreSQL major version that is still inside its support window on the day you go live, and plan its end of life before the stack ever reaches production. The supported versions are 18 (first released September 25, 2025, final release November 14, 2030), 17 (to November 8, 2029), 16 (to November 9, 2028), 15 (to November 11, 2027) and 14 (to November 12, 2026). Version 14 ends first, so a new deployment that starts on it would need an upgrade within months. Confirm the current list on the PostgreSQL versioning policy page before you pin the image tag, because the window you inherit determines how soon your next major upgrade is due.

Minor releases and major upgrades are different jobs. A minor release never changes the internal storage format, so you replace the executables and restart the server, and the data directory stays as it is. Your Compose file should pin a specific major and minor tag, such as postgres:17 with a patch level you record, and your team should apply minor updates on a routine schedule, since PostgreSQL ships minor releases at least once every three months. A major upgrade changes the storage format and needs a planned method: a dump and restore with pg_dumpall, pg_upgrade, or logical replication. Logical replication can keep downtime to several seconds, but it needs more setup and a rehearsal against a copy of your n8n data. Read the upgrade documentation before choosing.

Write the upgrade path into the plan before go-live, not after the first end-of-life warning. Record which method you will use, who runs it, how long the n8n stack can be paused, and how you will confirm that credentials, executions and workflows still work afterward. Also confirm with your team that the N8N_ENCRYPTION_KEY value and the database backup are preserved through the move, because a restored database without the matching key cannot decrypt stored credentials. Test the full sequence on a staging copy at least once, and keep the database version in your change calendar so the next major upgrade does not arrive as an emergency.

Security and operational controls for the Compose host

The Compose host is where n8n, its database and its sandbox services share one network and one disk. The controls below decide who can reach each port, how the database trusts its clients, how data is recovered, and who can read logs that may contain sensitive workflow output. Check each one on the running stack, not only in the Compose file.

Limit port exposure to the proxy

Publish only the reverse proxy's HTTPS port to the outside. The n8n editor and webhook port, the PostgreSQL port and any task runner listener should stay on the internal Docker network with no ports: mapping to the host. Confirm this with docker compose ps and by testing from another machine that the database and n8n ports do not answer. Also check the host firewall, because Docker can publish ports in ways that bypass some firewall rules you expect to apply. Ask your network team to verify the rules from outside the host.

n8n queue mode docs

Use SCRAM for database logins

PostgreSQL documents several client authentication methods, including password, GSSAPI, SSPI, LDAP, RADIUS, certificate, PAM and OAuth. For a Compose stack, the practical choice is a password method using SCRAM rather than MD5, with a dedicated role for n8n that owns only its database. Set password_encryption to scram-sha-256 and confirm that pg_hba.conf does not allow trust or MD5 for the n8n network. Store the password in a Docker secret or a file outside the Compose YAML, and rotate it through a planned change.

Current PostgreSQL major
18

Plan point-in-time recovery

A nightly pg_dump alone leaves a gap of up to a full day of executions and credential changes. PostgreSQL continuous archiving with a base backup and archived WAL files allows restore to a chosen point in time. Decide the archive destination, retention and who can trigger a restore. Then rehearse a restore into a separate container and time it. Confirm that backups of the n8nEncryptionKey material are stored separately, because a database backup without the key cannot decrypt stored credentials.

Continuous archiving docs

Restrict who reads container logs

Container logs can capture errors that include workflow payloads, webhook bodies or node output. Anyone who can run docker logs or read the Docker socket effectively has root on the host, so limit host access to a named group and avoid giving the n8n container access to the socket. Set a log driver with size limits so logs cannot fill the disk. Ask who receives logs from the host and whether those destinations are approved for the data your workflows handle.

Isolate the task runner and sandbox services

When the task runner runs as a separate service, it executes Code node JavaScript and Python on behalf of n8n. Keep it on the internal network only, drop unneeded capabilities, run it as a non-root user and set memory and CPU limits so runaway code cannot starve the host. Confirm that it cannot reach the database or other internal services unless a workflow design requires it. Record the image tag and review the sandbox configuration after each n8n upgrade.

Keep the host patched and volumes backed up

The host kernel, Docker Engine, the proxy and the base images receive security updates on their own schedule, separate from n8n and PostgreSQL releases. Document who applies them, how often you check, and how you roll back a failed update. Back up named volumes and bind mounts, including the n8n data directory and any custom certificates, and confirm the backup restores on a clean host. Ask your team to name the owner for each patch stream before go-live.

Questions teams ask before running n8n on Docker Compose

What drives the cost of running n8n on Docker Compose in production?

The main cost is the engineering time to build, harden and hand over the stack, plus the time your team spends operating it afterward. The n8n Community edition is free to self-host, so software licensing is not the same as total cost. Costs rise with the number of hosts, the database and backup design, the proxy and certificate setup, the encryption key handling, and how much testing your change process requires. DeployOpen does not publish prices. A quote follows from a written scope, so ask for the components listed, what is one-time work, and what recurs, such as upgrades and support.

How long does a production Docker Compose stack for n8n take to build?

Duration depends on the scope you agree in writing, not on a fixed template. The main factors are how many environments you need (for example, separate test and production), whether PostgreSQL, backups and TLS already exist in your infrastructure, how many integrations and credentials must be migrated, and how quickly your security and change approvers respond. Confirm with DeployOpen which milestones are included, such as build, verification and handover, and which items depend on your own access and approvals.

What does our team need to provide before a Compose engagement starts?

Plan to provide the infrastructure the stack will run on, including a Linux host or hosts in your cloud account or data center, DNS names, certificate authority or ACME access, and network rules. You will also need a named owner for the encryption key and secrets store, access to your identity provider if single sign-on is in scope, a backup target with retention rules, and a test workflow set that proves the instance works after each change. Confirm these dependencies in the written scope so timelines reflect them.

Can our own team build and run n8n on Docker Compose without a partner?

Yes, if you have people who can operate Docker, PostgreSQL, reverse proxies and secrets handling. The work is manageable for a small instance, but production adds decisions that are easy to get wrong: keeping the encryption key safe, pinning image tags, planning database upgrades, and testing restores. Consider whether your team can own these tasks after handover. A partner can close the gap for planning, build and verification, and then support upgrades under a retainer if you want continuity.

Which n8n license edition covers a Docker Compose deployment?

The free Community edition covers a self-hosted Compose stack, and n8n's Sustainable Use License allows use only for your own internal business purposes or for non-commercial or personal use. Files with .ee in their name or directory require a valid n8n Enterprise License. Features such as SSO and LDAP, environments with Git, and log streaming are listed on the pricing page for Business and Enterprise plans. Confirm with n8n which edition your use case needs before you plan features, and review the license terms with your legal team.

When should we move a Docker Compose n8n instance to queue mode?

Move to queue mode when a single main instance can no longer handle your trigger and execution volume, or when you need separate webhook processing and worker capacity. In queue mode, the main instance passes executions through Redis to workers that read and write PostgreSQL, so the encryption key must be shared with all worker and webhook processor nodes. Multi-main high availability is restricted to Enterprise self-hosted deployments. Measure your load first, and confirm the threshold and sizing with your own tests rather than a fixed rule.

How do we handle n8n version upgrades and PostgreSQL upgrades in a Compose stack?

Pin image tags so an upgrade is a deliberate change, and test each n8n minor release against your workflows before production. n8n uses semantic versioning and ships minor releases roughly weekly, so a schedule and a staging copy matter. For PostgreSQL, minor releases replace executables and restart the server, while major upgrades use dump and restore, pg_upgrade, or logical replication. Check the supported PostgreSQL versions on the versioning policy page before choosing a major version, and keep tested backups before every change.

What the Sustainable Use License means for a self-hosted stack

n8n is source-available, not open source. Its code is licensed under the Sustainable Use License, which allows use or modification only for your own internal business purposes or for non-commercial or personal use, and distribution only free of charge for non-commercial purposes. For a Docker Compose stack, that means the license covers the container you run for your own staff, but it does not automatically cover offering n8n as a service to customers, bundling it into a product you sell, or hosting it for other organizations. Read the license text yourself before you commit a design, and check any use that involves external clients or embedded workflows.

Some files carry a separate condition. Anything with .ee in its file or directory name is not covered by the Sustainable Use License and needs a valid n8n Enterprise License. Compose itself does not reveal which code paths you touch, so check the image you pin and the features you enable against n8n's license documentation. Several capabilities that a production stack often needs sit behind paid plans: SSO and LDAP, environments with Git, and log streaming are listed on the Business and Enterprise plans, and multi-main setup for high availability is restricted to Enterprise self-hosted deployments. If your design depends on any of these, the Compose file alone will not provide them.

Confirm the license position in writing before you build. Ask n8n which edition and license terms apply to your use case, including internal use by several business units, any contractor or partner access, and any workflows that serve external users. Put the same questions to your legal counsel, and record the answers next to the stack's configuration so the next upgrade or staffing change does not reopen them. Ask your delivery partner to flag every enabled feature that depends on a paid plan, so the license review covers the stack as it will actually run.

How DeployOpen scopes and delivers n8n on Docker Compose

DeployOpen plans and builds the Compose stack for n8n inside infrastructure you control, from the PostgreSQL database and encryption key handling to the task runner, pinned image tags and restart policies. Each engagement is fixed-scope, so the stack, the handover documents and the test evidence are agreed in writing before the build starts.

How we scope

  • Written scope names the hosts, network zones, proxy and certificate approach, and the n8n edition you run.
  • We confirm whether the stack stays single-instance or needs queue mode workers, and record that decision in the scope.
  • We agree which n8n features your team needs and confirm which of them require a paid plan before design starts.

How we build

  • We deploy n8n on PostgreSQL with persistent volumes, a managed encryption key and pinned image tags.
  • We configure the task runner and sandbox services, then test workflow execution, credential access and restarts.
  • We check restart policies and health behavior against the failure cases agreed in the scope before handover.

How we hand over

  • You receive the Compose files, environment configuration templates and a runbook for backups and key storage.
  • Test results show which workflows, restarts and recovery steps were verified against the agreed scope.
  • We walk your platform and security teams through the upgrade and rollback steps so your team can run the stack.

How we support

  • Ongoing support, upgrades and continuous testing are available as a retainer after handover.
  • Retainers can cover planned n8n minor version updates, PostgreSQL patching and periodic configuration reviews.
  • Ask us to confirm response terms and what is included in a retainer before you sign the written agreement.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.