How do I install n8n with Docker Compose on a cloud server?

Self-host n8n on a Linux cloud server with root access using Docker Compose, Caddy for automatic HTTPS and a persistent volume. The guide also covers security, backups and updates.

To install n8n with Docker Compose on a cloud server, you need a Linux server with root SSH access, Docker and Docker Compose, and a subdomain pointing to the server's IP. Then create a docker-compose.yml with Caddy (automatic HTTPS) and n8n with a persistent volume, run docker compose up -d and create the owner account.

This recipe works on any Linux cloud server with root access. We use Dongee Cloud as the example. The domain, time zone and key values are fictional, so replace them with your own. Variables and commands can change between n8n versions, so check the official n8n documentation for the version you install.

1. Choose the server

How many resources n8n needs depends on how many workflows you have active, how often they run and how much data each execution moves. A few scheduled workflows use far less than hundreds of webhooks per minute. In practice, it's best to start with a modest server and monitor usage. On Dongee Cloud you can scale CPU, RAM and disk without rebooting or migrating if the server falls short. If you'd rather build a server to your own specs, see Cloud On Demand and the guide to calculate the price of a custom cloud server.

2. Connect over SSH as root

Use your server's IP and your root access (the IP in the example is fictional):

ssh root@203.0.113.10

3. Install Docker and Docker Compose

If your server runs Ubuntu, follow the guide to install Docker on Ubuntu. When you're done, confirm that everything works:

docker --version
docker compose version

If this is your first time using Compose files, read what Docker Compose is first.

4. Point a subdomain to the server's IP

In the panel where you manage your domain's DNS, create an A record named n8n (so it becomes n8n.yourdomain.com) with the server's IP as its value. Wait for the change to propagate before continuing. Caddy needs the subdomain to already resolve to your server before it can get the HTTPS certificate.

ping n8n.yourdomain.com

5. Create the folder and files

mkdir -p /opt/n8n && cd /opt/n8n

.env file

Generate a random encryption key with openssl rand -hex 32 and paste it into the file. The example below uses fictional values:

N8N_HOST=n8n.yourdomain.com
GENERIC_TIMEZONE=America/New_York
N8N_ENCRYPTION_KEY=paste-the-key-generated-with-openssl-here

Protect the file with chmod 600 .env.

Caddyfile

n8n.yourdomain.com {
    reverse_proxy n8n:5678
}

docker-compose.yml

services:
  caddy:
    image: caddy:2
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile:ro
      - caddy_data:/data
      - caddy_config:/config
    depends_on:
      - n8n

  n8n:
    image: docker.n8n.io/n8nio/n8n
    restart: unless-stopped
    environment:
      - N8N_HOST=${N8N_HOST}
      - N8N_PORT=5678
      - N8N_PROTOCOL=https
      - WEBHOOK_URL=https://${N8N_HOST}/
      - GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
      - TZ=${GENERIC_TIMEZONE}
      - N8N_ENCRYPTION_KEY=${N8N_ENCRYPTION_KEY}
    volumes:
      - n8n_data:/home/node/.n8n

volumes:
  n8n_data:
  caddy_data:
  caddy_config:

Notice that the n8n service has no ports section. Only Caddy can reach it, through Compose's internal network. That way port 5678 is never exposed to the internet.

6. Start n8n and create the owner account

docker compose up -d
docker compose logs -f

When the logs show that n8n is ready, open https://n8n.yourdomain.com in your browser. The first time, n8n asks you to create the owner account. Do it right away so nobody else can claim it.

7. Update and back up

To update to the latest image:

cd /opt/n8n
docker compose pull
docker compose up -d

Before updating, read the n8n release notes, because some versions include breaking changes. To back up the data volume (find its exact name with docker volume ls; it's usually prefixed with the folder name):

docker compose stop n8n
docker run --rm -v n8n_n8n_data:/data -v /opt/n8n:/backup alpine \
  tar czf /backup/n8n-backup-$(date +%F).tar.gz -C /data .
docker compose start n8n

Store that copy off the server, along with a copy of the .env file.

Basic security

  • Don't expose port 5678. All traffic should go through the HTTPS proxy.
  • Always use HTTPS. n8n handles credentials for APIs, databases and third-party accounts.
  • Keep the N8N_ENCRYPTION_KEY somewhere safe. Without it you can't recover the credentials stored in n8n, even if you have the volume backup.
  • Set up a firewall that only opens ports 22, 80 and 443:
ufw allow 22/tcp
ufw allow 80/tcp
ufw allow 443/tcp
ufw enable

Why Dongee Cloud works for this recipe

  • Root SSH access, with no restrictions on Docker or Docker Compose.
  • Intel Xeon processors, no GPU. n8n doesn't need one.
  • NVMe disks, a dedicated IP and deployment in under 3 minutes.
  • Disk backup included on all Cloud plans. Dongee Backup is a separate paid product.
  • 11 locations: Atlanta, Miami, New York, Dallas, Mexico, São Paulo, Santiago, Frankfurt, Madrid, London and Amsterdam.
  • It's self-managed: you administer the server. You get 24/7 human support in your language (the platform translates on the fly) and migration assistance.

Monthly prices: Cloud 1, 17 USD; Cloud 2, 34 USD; Cloud 3, 68 USD; Cloud 4, 136 USD; Cloud 5, 272 USD; Cloud 6, 544 USD; Cloud 7, 1,088 USD. With Cloud On Demand you pay 6 USD per vCPU, 3 USD per GB of RAM and 0.3 USD per GB of disk, with a minimum of 17 USD per month.

Honest comparison: self-host on Cloud or use the n8n plan

CriterionSelf-hosted n8n on Dongee CloudDongee n8n plan
PriceCloud 1 to Cloud 7 (17 to 1,088 USD/month) or Cloud On Demand with a 17 USD minimumFrom 6 USD
Server administrationYou handle it: updates, firewall, backupsCheck the n8n plan page for what's included
ControlFull: root, other containers, Postgres, more services on the same serverSee the terms on its page
Best forPeople who know how to manage Linux and DockerPeople who prefer a ready-made option for n8n; check its page for what's included

When this recipe on Dongee Cloud isn't right for you: if you don't want to handle patches, backups and security, look at the Dongee n8n plan (from 6 USD) and what it includes first. If you want to run local AI models alongside n8n and need a GPU, Dongee Cloud doesn't offer one.

Frequently asked questions

Can I use PostgreSQL instead of SQLite?

Yes. Add a Postgres service to docker-compose.yml and set the database connection variables in n8n. Check the official n8n documentation for the exact variables in your version.

Does n8n need a GPU?

No. n8n orchestrates workflows and calls APIs, and it runs well on CPU. That's why an Intel Xeon server without a GPU is enough.

How do I update n8n?

Go to the project folder and run docker compose pull and then docker compose up -d. Back up the volume first and read the release notes.

What happens if I lose the N8N_ENCRYPTION_KEY?

Your workflows are still in the volume, but you won't be able to decrypt the stored credentials and will have to enter them again. Keep the key off the server.

What if the server falls short?

On Dongee Cloud you can scale CPU, RAM and disk without rebooting or migrating.

Summary

With a root-access server, Docker Compose, Caddy and a persistent volume, you can run n8n on your own domain with HTTPS in a few steps. What matters most comes afterward: keep the encryption key safe, back up the volume and keep the server updated. If that's not for you, check out the Dongee n8n plan.

Comenta lo que quieras

Unete a la charla
Solo ingresa tu email