CALIBRATING SYSTEMS
Home / Blog / n8n Self Hosted Docker Setup: Install n8n With Docker Compose
Guides

n8n Self Hosted Docker Setup: Install n8n With Docker Compose

· 6 min read · Ali Raza Abro

To run n8n self hosted with Docker, you need a Linux server with Docker Engine and Docker Compose, a subdomain pointed at the server, and a Compose setup that runs the n8n container behind a reverse proxy for HTTPS. n8n's own documentation now recommends Docker Compose over a single docker run command, and its example uses Traefik to handle routing and SSL certificates, with a persistent volume mounted at /home/node/.n8n so your workflows, credentials and encryption key survive restarts. Once it is up, n8n is available at your subdomain on port 443, and the container listens internally on port 5678.

I set up self-hosted n8n for clients who want data control or lower cost at volume. This guide walks through the setup in the order I do it, based on the official n8n Docker Compose guide, plus the production details the quick start leaves out. Read it alongside the official docs, because environment variables and defaults change between n8n versions.

Before you start: is self-hosting right?

n8n's documentation is clear that self-hosting needs server experience, and recommends n8n Cloud if you are not comfortable managing servers. You become responsible for security, updates, backups and uptime. If that sounds like a burden, read n8n self hosted vs cloud first.

If you go ahead, plan for:

  • A small VPS from any reputable provider. Size depends on your workload, and AI-heavy or high-concurrency workflows need more memory.
  • A domain you control, with the ability to add DNS records.
  • Someone who will apply updates and check backups regularly.

Step 1: Prepare the server

  1. Create a Linux VPS. Ubuntu LTS is a common, well-documented choice.
  2. Create a non-root user with sudo access, and log in with SSH keys rather than passwords.
  3. Enable a firewall that allows only SSH, HTTP (80) and HTTPS (443). Port 80 is needed for certificate issuance.
  4. Install Docker Engine and the Docker Compose plugin using Docker's official instructions for your distribution.
  5. Verify with docker --version and docker compose version.
  6. Optionally add your user to the docker group so you can run Docker without sudo.

Step 2: Point DNS at the server

Create a DNS A record for the subdomain you want to use, for example n8n.youragency.com, pointing to the server's public IP address. Wait for it to resolve before continuing, because the reverse proxy needs it to issue a certificate.

Step 3: Create the project folder

Following n8n's guide:

  1. Create a project folder, for example n8n-compose.
  2. Inside it, create an .env file for configuration.
  3. Create a compose.yaml file for the services.
  4. Create a local-files subfolder, which is mounted into the container so n8n can read and write files on the host.

Step 4: Set the environment variables

n8n's Docker Compose guide uses these variables in the .env file:

  • DOMAIN_NAME: your top-level domain, such as youragency.com.
  • SUBDOMAIN: the subdomain, such as n8n. Together these form the address, https://n8n.youragency.com.
  • SSL_EMAIL: the email used when creating the TLS certificate.
  • GENERIC_TIMEZONE: the time zone for schedule-based nodes. Set this to your agency's time zone, or schedules will run in the default.

Keep the .env file out of any shared repository, since it will hold sensitive settings.

Step 5: Write the Compose file

Copy the compose.yaml from n8n's official guide rather than an old blog post, because image names, recommended variables and proxy settings change. The official example defines two services:

  • Traefik, the reverse proxy, which listens on ports 80 and 443, gets certificates from Let's Encrypt, and stores certificate data in a traefik_data volume.
  • n8n, using the official n8n image, with an n8n_data volume mounted at /home/node/.n8n and the local-files folder mounted at /files.

The n8n_data volume is the important one. It holds the default SQLite database and the encryption key used to protect your credentials. Lose it and you lose your workflows and the ability to decrypt saved credentials.

Step 6: Start n8n

From the project folder, run docker compose up -d. Docker pulls the images and starts both containers in the background. After a minute, visit https://n8n.youragency.com. You should see the n8n setup screen, where you create the owner account.

To stop it, run docker compose stop.

If the page does not load, check:

  1. DNS resolves to the server.
  2. Ports 80 and 443 are open in the firewall and at the VPS provider.
  3. Container logs, with docker compose logs, for certificate or startup errors.

Step 7: Production settings worth adding

The quick start gets you running. For production, I also consider:

Postgres instead of SQLite

SQLite is fine for light use. For heavier workloads, n8n supports PostgreSQL through DB_TYPE and the DB_POSTGRESDB variables documented in n8n's Docker docs. The n8n-hosting repository on GitHub includes a Compose example with Postgres. Keep the n8n_data volume mounted even with Postgres, because it still holds the encryption key.

Encryption key backup

Note where the encryption key lives and back it up securely, separately from the server. If you ever restore to a new server without it, your saved credentials will not decrypt.

File permissions

n8n's docs mention N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS for enforcing secure permissions on the settings file. Check the current docs for whether your version needs it.

Execution data pruning

Saved execution data grows. n8n has settings to prune old executions. Configure them so the database does not fill the disk.

Webhook URL

If n8n sits behind a proxy and webhook URLs show the wrong address, set the webhook URL variable described in n8n's docs so production webhook URLs use your public domain.

Step 8: Updates

To update a Compose deployment, n8n's docs describe pulling the new image and recreating the container: docker compose pull, then docker compose down, then docker compose up -d. Before updating:

  1. Read the release notes for breaking changes, especially for major versions.
  2. Back up the n8n_data volume and the database.
  3. Update during a quiet window and test key workflows afterwards.

My guide to n8n backup and update covers this routine in more detail.

Step 9: Backups and security

Minimum backup routine:

  • Daily backup of the database (the SQLite file in n8n_data, or a Postgres dump).
  • Export workflows regularly, or keep them in source control.
  • Store backups off the server.
  • Test a restore at least once.

Security basics:

  • Keep the server and Docker updated.
  • Use strong owner credentials and enable two-factor authentication if your version supports it.
  • Do not expose the database port publicly.
  • Limit who has SSH access.

See n8n self-hosted security for a fuller checklist.

How to install n8n self hosted without Compose

n8n's docs still show a single docker run command that creates an n8n_data volume and maps port 5678, but they now mark that guide as outdated and recommend Compose. A single container on port 5678 without a proxy is fine for trying n8n on your laptop. Do not expose it to the internet like that, because you need HTTPS for webhooks and to protect logins.

After setup: what to build first

Once n8n is running, good first workflows for an agency include a webhook-to-Slack lead alert, a scheduled report, or an AI agent that answers questions from your docs. See n8n workflow examples for ideas.

How I build this

I set up self-hosted n8n with HTTPS, Postgres, backups and update routines, then build the workflows on top with error alerts and documentation. See my workflow automation and custom AI agents services, check pricing, or request a free 15-minute Loom teardown if you already have an n8n server you are unsure about.

FAQ

How do I install n8n self hosted?

Prepare a Linux server with Docker and Docker Compose, point a subdomain at it, and follow n8n's official Docker Compose guide, which runs n8n behind Traefik for HTTPS with a persistent data volume.

What port does n8n use in Docker?

The n8n container listens on port 5678. In a production setup, a reverse proxy serves it over HTTPS on port 443.

Is n8n self hosted free?

The community edition can be self-hosted under n8n's sustainable use license, so you pay for your server rather than per execution. Paid self-hosted plans add team and enterprise features.

How do I update n8n in Docker Compose?

Back up first, then run docker compose pull, docker compose down and docker compose up -d from the project folder, and test your key workflows afterwards.

Do I need Postgres for n8n?

No. n8n uses SQLite by default, which is fine for light use. Postgres is recommended for heavier production workloads.

Show me the workflow you hate.

Send one workflow and get a free 15-minute Loom teardown, or book a call if you’d rather talk it through.