Back to blog
Self-Hosted n8n

How to Deploy n8n Docker on a Self-Hosted VPS? 

Oct 6, 2026

Running n8n Docker on a self-hosted VPS gives you control over your automation environment, data, workflows and server resources. Your n8n instance can remain online around the clock, execute scheduled workflows and receive webhooks without depending on your local computer.

You can build the environment manually with n8n Docker Compose, or use the Time4VPS n8n deployment template to reduce the initial setup work. In this guide, we explain both approaches and provide practical configuration examples.

What is n8n Docker?

n8n is a workflow automation platform that connects applications, APIs, databases and other services. You can use it to synchronise data, process orders, generate reports, send operational notifications or build AI-powered workflows.

Docker packages n8n and its dependencies inside a container. This creates an isolated and reproducible environment that can be moved, restarted or updated without installing n8n directly on the VPS operating system.

A typical n8n Docker deployment can include several components:

  • The n8n application
  • A PostgreSQL database
  • A reverse proxy such as Traefik
  • HTTPS certificates
  • Persistent Docker volumes
  • Environment variables and encryption keys

What is n8n Docker Compose?

Docker Compose lets you define and manage multiple containers through a single compose.yaml file. Instead of starting n8n, PostgreSQL and Traefik separately, you describe the entire stack in one configuration.

With n8n Docker Compose, you can start the complete environment using one command:

docker compose up -d

The -d option runs the containers in the background, allowing n8n to continue operating after you disconnect from the VPS.

The official n8n Docker Compose documentation also provides an example deployment with persistent storage, Traefik and HTTPS.

Why run n8n Docker on a VPS?

Running n8n on a VPS provides an always-available environment for workflows that need to operate continuously. It also gives you more control than running n8n locally or using a restricted hosting environment.

The main benefits include:

  • 24/7 workflow execution: Scheduled workflows can run even when your computer is switched off.
  • Webhook availability: External applications can send data to a public HTTPS endpoint.
  • Control over your data: You decide where the application and its database are hosted.
  • Dedicated server resources: Your n8n instance uses the CPU, memory and storage included with your VPS.
  • Persistent storage: Workflows, credentials and execution data remain available after containers restart.
  • Flexible configuration: You can change environment variables, install supporting tools and configure the server for your workload.
  • Simpler updates: Docker images can be updated without manually reinstalling the complete application.

A self-hosted n8n VPS is particularly suitable for developers, system administrators, automation professionals and technical teams that are comfortable managing a Linux server.

What do you need before deploying n8n Docker?

For a manual deployment, you will need:

  • A Linux VPS with sufficient resources for your workflows
  • Root or sudo access
  • Docker Engine and Docker Compose
  • A domain or subdomain pointed to the VPS
  • Basic familiarity with SSH and Linux commands
  • A plan for server security, updates, monitoring and backups

At Time4VPS, our Linux VPS plans provide full root access and scalable server resources. This allows you to configure the n8n Docker environment according to your requirements.

Deploy n8n Docker faster with Time4VPS

If you do not want to build the entire n8n Docker Compose stack manually, Time4VPS offers an n8n deployment template for a self-managed VPS.

The template uses Ubuntu 24.04 and Docker, with n8n preinstalled. It prepares the main components required to start using your self-hosted n8n instance, reducing setup time and the risk of configuration errors.

To install the template:

  1. Log in to the Time4VPS Client Area.
  2. Open Services → VPS.
  3. Select Manage next to your VPS.
  4. Click Install OS.
  5. Choose n8n (Ubuntu 24.04, Docker) (64-bit).
  6. Confirm the installation and wait for the process to finish.

The installation normally takes between 10 and 20 minutes. Once completed, connect to the server through SSH:

ssh root@your_server_ip

Replace your_server_ip with the IP address assigned to your VPS.

The automatically generated access details are stored in:

/root/n8n_logins

You can display them with:

cat /root/n8n_logins

After retrieving the credentials, open the hostname assigned to your server:

https://your_hostname.time4vps.cloud

Enter the additional access credentials and then create the owner account for your n8n dashboard. The complete process is available in our Time4VPS n8n template guide.

How to create an n8n Docker Compose deployment manually

The Time4VPS template is the faster option, but you can also create your own deployment when you need a customised configuration.

The following example uses:

  • n8n
  • PostgreSQL
  • Traefik
  • Let’s Encrypt HTTPS certificates
  • Persistent Docker volumes

Step 1: Point a subdomain to your VPS

Create an A record in your DNS settings:

Type: A
Name: n8n
Value: your_server_ip

This example makes n8n available at:

https://n8n.example.com

DNS changes may require some time to become active.

Step 2: Connect to the VPS

Connect through SSH:

ssh root@your_server_ip

Verify that Docker and Docker Compose are available:

docker –version
docker compose version

If either command is unavailable, install the current supported version by following Docker’s official instructions for your Linux distribution.

Step 3: Create the project directory

Create a separate directory for the n8n Docker deployment:

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

Create an environment file:

nano .env

Add the following values:

N8N_HOST=n8n.example.com
GENERIC_TIMEZONE=Europe/Vilnius
[email protected]

POSTGRES_DB=n8n
POSTGRES_USER=n8n
POSTGRES_PASSWORD=replace_with_a_long_random_password

N8N_ENCRYPTION_KEY=replace_with_a_long_random_encryption_key

Replace the example domain, email address, timezone and passwords with your own values.

You can generate random values using:

openssl rand -hex 32

Run the command separately for the PostgreSQL password and n8n encryption key. Then restrict access to the file:

chmod 600 .env

Keep the encryption key safe. n8n uses it to encrypt saved credentials, so losing or unexpectedly changing it can make those credentials unusable.

Step 4: Create the n8n Docker Compose file

Create the Compose file:

nano compose.yaml

Add the following configuration:

services: 
  postgres: 
    image: postgres:16 
    restart: unless-stopped 
    environment: 
      POSTGRES_DB: ${POSTGRES_DB} 
      POSTGRES_USER: ${POSTGRES_USER} 
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} 
    volumes: 
      – postgres_data:/var/lib/postgresql/data 
    healthcheck: 
      test: 
        – CMD-SHELL 
        – pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB} 
      interval: 5s 
      timeout: 5s 
      retries: 10 
    networks: 
      – internal 
 
  n8n: 
    image: docker.n8n.io/n8nio/n8n:stable 
    restart: unless-stopped 
    environment: 
      DB_TYPE: postgresdb 
      DB_POSTGRESDB_HOST: postgres 
      DB_POSTGRESDB_PORT: 5432 
      DB_POSTGRESDB_DATABASE: ${POSTGRES_DB} 
      DB_POSTGRESDB_USER: ${POSTGRES_USER} 
      DB_POSTGRESDB_PASSWORD: ${POSTGRES_PASSWORD} 
 
      N8N_HOST: ${N8N_HOST} 
      N8N_PORT: 5678 
      N8N_PROTOCOL: https 
      N8N_WEBHOOK_URL: https://${N8N_HOST}/ 
      N8N_PROXY_HOPS: 1 
 
      GENERIC_TIMEZONE: ${GENERIC_TIMEZONE} 
      TZ: ${GENERIC_TIMEZONE} 
      N8N_ENCRYPTION_KEY: ${N8N_ENCRYPTION_KEY} 
      N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS: “true” 
    volumes: 
      – n8n_data:/home/node/.n8n 
    depends_on: 
      postgres: 
        condition: service_healthy 
    labels: 
      – “traefik.enable=true” 
      – “traefik.docker.network=n8n_proxy” 
      – “traefik.http.routers.n8n.rule=Host(`${N8N_HOST}`)” 
      – “traefik.http.routers.n8n.entrypoints=websecure” 
      – “traefik.http.routers.n8n.tls=true” 
      – “traefik.http.routers.n8n.tls.certresolver=letsencrypt” 
      – “traefik.http.services.n8n.loadbalancer.server.port=5678” 
    networks: 
      – internal 
      – proxy 
 
  traefik: 
    image: traefik:v3 
    restart: unless-stopped 
    command: 
      – “–providers.docker=true” 
      – “–providers.docker.exposedbydefault=false” 
      – “–entrypoints.web.address=:80” 
      – “–entrypoints.web.http.redirections.entrypoint.to=websecure” 
      – “–entrypoints.web.http.redirections.entrypoint.scheme=https” 
      – “–entrypoints.websecure.address=:443” 
      – “–certificatesresolvers.letsencrypt.acme.tlschallenge=true” 
      – “–certificatesresolvers.letsencrypt.acme.email=${SSL_EMAIL}” 
      – “–certificatesresolvers.letsencrypt.acme.storage=/letsencrypt/acme.json” 
    ports: 
      – “80:80” 
      – “443:443” 
    volumes: 
      – traefik_data:/letsencrypt 
      – /var/run/docker.sock:/var/run/docker.sock:ro 
    networks: 
      – proxy 
 
volumes: 
  postgres_data: 
  n8n_data: 
  traefik_data: 
 
networks: 
  internal: 
    name: n8n_internal 
  proxy: 
    name: n8n_proxy 
 

The N8N_WEBHOOK_URL value tells n8n which public address external services should use for webhooks. Because Traefik acts as a reverse proxy, N8N_PROXY_HOPS is set to 1. These settings follow n8n’s current reverse-proxy configuration guidance.

Step 5: Check the configuration

Before starting the containers, validate the configuration:

docker compose config

If the command returns the resolved configuration without an error, pull the required images:

docker compose pull

Start the n8n Docker Compose stack:

docker compose up -d

Check the status of the containers:

docker compose ps

All three services should be running. You can inspect the n8n logs with:

docker compose logs –tail=100 n8n

To follow new log entries in real time, use:

docker compose logs -f n8n

Press Ctrl + C to stop following the logs. This does not stop the n8n container.

Step 6: Configure the firewall

Your VPS should allow SSH, HTTP and HTTPS traffic. On Ubuntu with UFW, the commands are:

ufw allow OpenSSH
ufw allow 80/tcp
ufw allow 443/tcp
ufw enable
ufw status

Confirm that SSH access is working correctly before enabling the firewall. Otherwise, you could lock yourself out of the server.

Step 7: Open n8n

Visit your chosen subdomain:

https://n8n.example.com

Traefik will request the HTTPS certificate, and n8n will display the owner-account setup screen. Create your account before connecting applications or activating workflows.

How to update n8n Docker

Before updating, back up your database, persistent data and configuration. You should also review the n8n release notes for breaking changes.

To download the current image and recreate the container, run:

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

Docker Compose preserves the named volumes, but this does not replace a proper backup strategy.

A basic PostgreSQL database export can be created with:

mkdir -p /root/n8n-backups

docker compose exec -T postgres \
sh -c ‘pg_dump -U “$POSTGRES_USER” “$POSTGRES_DB”‘ \
>/root/n8n-backups/n8n-$(date +%F).sql

Your backup plan should cover:

  • The PostgreSQL database
  • The n8n persistent volume
  • The .env file
  • The n8n encryption key
  • Any local files used by workflows

Test your restore procedure before relying on the deployment for important workflows.

Self-hosted does not mean fully managed

Whether you deploy n8n Docker manually or select the Time4VPS template, the VPS remains self-managed.

You are responsible for:

  • Linux server administration
  • n8n and operating-system updates
  • Firewall and SSH configuration
  • Monitoring resource usage
  • Protecting credentials and encryption keys
  • Configuring and verifying backups
  • Maintaining workflows and integrations
  • Troubleshooting n8n and connected services

Time4VPS provides the VPS infrastructure and the n8n deployment template, but it is not a fully managed n8n service.

Frequently Asked Questions

What is the difference between n8n Docker and n8n Docker Compose?

Docker can run an individual n8n container. Docker Compose defines and manages multiple related services, such as n8n, PostgreSQL and Traefik, through one configuration file.

Can n8n Docker run continuously on a VPS?

Yes. A VPS can keep the n8n container running around the clock, allowing scheduled workflows and webhooks to operate without relying on your personal computer.

Do I need a domain to use n8n Docker?

A domain or subdomain is recommended for a manual public deployment because it provides a stable address for HTTPS and webhooks. The Time4VPS n8n template can also be accessed through the hostname assigned to the VPS.

Is the Time4VPS n8n VPS managed?

No. The Time4VPS n8n template is installed on a self-managed VPS. n8n is preinstalled, but you remain responsible for server administration, security, updates, backups and workflow management.

Why use the Time4VPS n8n template?

The template reduces the number of manual installation steps required to launch n8n Docker. It is suitable for users who want a prepared starting environment while retaining full control of their VPS and n8n configuration.

Start your self-hosted n8n VPS with Time4VPS

A correctly configured n8n Docker deployment provides a flexible environment for running workflows, receiving webhooks and connecting applications. Docker Compose makes the individual components easier to organise, while a VPS keeps your automation platform available continuously.

With the Time4VPS n8n template, you can avoid much of the initial installation work and start with n8n already deployed on an Ubuntu 24.04 Docker environment. Choose a VPS plan, install the n8n template and begin building your self-hosted automation workflows.

Start working on your project today!

With our easy to install solutions and exquisite customer support your VPS will be up and running in 10 minutes!

Choose your plan