Installing n8n with Docker Compose on a VPS

n8n is installed on a VPS with Docker Compose: one file describes the container, one command starts it, and the interface appears on port 5678. This article shows what the file needs and why. The details that change between versions are in the official n8n documentation, which you should check for the current version.

n8n is third-party software. Installing and maintaining it is your side, on an unmanaged VPS. We do not sell n8n and our support does not install or repair it. See how far our support goes.

Before you start

1 A VPS with root access over SSH and Docker with Docker Compose installed. If you do not have them yet, follow installing Docker and Docker Compose on a VPS.
2 A domain name, if you want to use n8n properly with HTTPS (the next article in the series, n8n behind HTTPS on your own domain). For a first trial, the IP address will do.
3 An encryption key generated by you. A common way is openssl rand -hex 32, which prints a random string. Keep it in a password manager, off the server.

What the compose file needs

In a folder of its own (for example /opt/n8n) create a compose.yaml file with a single service. These are the points that matter:

Field What to put Why
image The official n8n image, with a pinned version. A pinned version prevents surprise jumps. The exact image name and versions are in the official documentation.
ports 127.0.0.1:5678:5678 The interface is reachable only from the server itself. The HTTPS proxy gets in, not the internet.
environment N8N_ENCRYPTION_KEY, WEBHOOK_URL, GENERIC_TIMEZONE The key protects the credentials; the public address tells n8n which URL to show for webhooks; the time zone puts schedules at the right hour.
volumes A persistent volume mounted on the n8n data folder. Without it, workflows and credentials vanish when the container is recreated.
restart Restart always, unless stopped by hand. n8n comes back by itself after the server reboots.

Start it and check

1 In the folder of the file, run docker compose up -d. Docker downloads the image and starts the service in the background.
2 Confirm with docker compose ps that the service is running, and with docker compose logs that startup shows no errors.
3 While there is no HTTPS yet, come in through an SSH tunnel rather than opening the port to the world: ssh -L 5678:localhost:5678 user@server-address, then open http://localhost:5678 on your computer.
4 On the first visit n8n asks you to create the owner account. Pick a strong, unique password.
Do not lose or change the encryption key. With a different key n8n can no longer read the stored credentials. And do not expose port 5678 straight to the internet without HTTPS: the owner login and the credentials would travel in the clear. See ports and firewall on a VPS.
Back up the compose folder from day one, with the data volume. See backing up n8n.

The VPS does not answer, or the address does not reach the machine? Open a ticket and we will check the server.

Open a support ticket

SEE ALSO

VPS servers

n8n behind HTTPS on your own domain

Docker Compose: an application with its database

Backing up n8n

RECOMMENDED PRODUCT

VPS server with root access

Resources of your own, the OS you choose, reinstall whenever you like. from $7.61/mo (3-year plan, with coupon)

See plans
  • 0 Users Found This Useful
Was this answer helpful?