How to Install n8n with Docker Compose v2.29 on Ubuntu 24.04
Learning how to install n8n on an Ubuntu 24.04 server using Docker Compose v2.29 requires configuring environment variables, establishing persistent volume storage, setting up PostgreSQL 16 for production-grade reliability, and deploying a reverse proxy for TLS termination. While running a self hosted n8n instance gives developers granular control over node execution environments, maintaining infrastructure long term introduces operational overhead, security patching duties, and database optimization tasks.
1. Prerequisites and Ubuntu 24.04 Server Preparation
Before deploying n8n via Docker, configure your base operating system with necessary security policies and repository packages. Start by updating your system package index and setting up Uncomplicated Firewall (UFW) to limit exposed ports.
Execute the following commands on your freshly provisioned Ubuntu 24.04 LTS instance:
- Update system packages:
sudo apt update && sudo apt upgrade -y - Install essential tools for handling SSL certificates and container management:
sudo apt install -y curl git ufw ca-certificates gnupg lsbug-release - Configure UFW rules to allow SSH traffic alongside HTTP and HTTPS protocols:
sudo ufw allow 22/tcp sudo ufw allow 80/tcp sudo ufw allow 443/tcp sudo ufw enable
Install the official Docker Engine repository to ensure compatibility with Docker Compose v2.29 rather than using outdated distribution packages:
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Verify that Docker daemon is active and running under systemd by checking its operational status with sudo systemctl status docker.
2. Docker Compose Setup for Self Hosted n8n
Creating a structured container architecture isolates the application layer from the persistent storage volumes. Default SQLite deployments frequently encounter database locking issues during concurrent workflow runs. Production self hosted n8n environments should always deploy alongside PostgreSQL 16.
Create a dedicated working directory on your filesystem:
mkdir -p ~/n8n-docker && cd ~/n8n-docker
Create a file named docker-compose.yml using your preferred text editor and add the following specification:
version: '3.8'
services:
postgres:
image: postgres:16-alpine
restart: always
environment:
POSTGRES_USER: ${DB_POSTGRESDB_USER}
POSTGRES_PASSWORD: ${DB_POSTGRESDB_PASSWORD}
POSTGRES_DB: ${DB_POSTGRESDB_DATABASE}
volumes:
- postgres_storage:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -h localhost -U ${DB_POSTGRESDB_USER} -d ${DB_POSTGRESDB_DATABASE}"]
interval: 5s
timeout: 5s
retries: 10
n8n:
image: docker.n8n.io/n8nio/n8n:latest
restart: always
ports:
- "127.0.0.1:5678:5678"
environment:
- DB_TYPE=postgresdb
- DB_POSTGRESDB_HOST=postgres
- DB_POSTGRESDB_PORT=5432
- DB_POSTGRESDB_DATABASE=${DB_POSTGRESDB_DATABASE}
- DB_POSTGRESDB_USER=${DB_POSTGRESDB_USER}
- DB_POSTGRESDB_PASSWORD=${DB_POSTGRESDB_PASSWORD}
- N8N_HOST=${SUBDOMAIN}.${DOMAINNAME}
- N8N_PORT=5678
- N8N_PROTOCOL=https
- NODE_ENV=production
- WEBHOOK_URL=https://${SUBDOMAIN}.${DOMAINNAME}/
- GENERIC_TIMEZONE=UTC
- EXECUTIONS_DATA_SAVE_ON_ERROR=all
- EXECUTIONS_DATA_SAVE_ON_SUCCESS=all
- EXECUTIONS_DATA_PRUNE=true
- EXECUTIONS_DATA_MAX_AGE=168
links:
- postgres
depends_on:
postgres:
condition: service_healthy
volumes:
- n8n_storage:/home/node/.n8n
volumes:
postgres_storage:
n8n_storage:
Tip: Always map the n8n application service port specifically to `127.0.0.1:5678` rather than `5678:5678`. This prevents unauthenticated public access directly to the internal Node.js express engine before traffic passes through your HTTPS reverse proxy.
3. Configuring Environment Variables for PostgreSQL 16 and SSL
Docker Compose references configuration parameters stored in a local .env file. Storing secret values and hostname definitions inside `.env` keeps your runtime settings isolated from source repositories.
Create a .env file inside the ~/n8n-docker folder containing these operational parameters:
# Domain Settings
DOMAINTYPE=com
DOMAINNAME=example.com
SUBDOMAIN=n8n
# PostgreSQL Credentials
DB_POSTGRESDB_DATABASE=n8ndb
DB_POSTGRESDB_USER=n8ndbuser
DB_POSTGRESDB_PASSWORD=SuperSecretComplexPassword123!
# Encryption Key for Credentials (Generated Automatically if Left Blank)
N8N_ENCRYPTION_KEY=a8f9b2c3d4e5f6a7b8c9d0e1f2a3b4c5
Key environment parameters that directly govern n8n processing stability include:
WEBHOOK_URL: Must match your public domain endpoint exactly. Mismatched webhook URLs break external integrations using Stripe Trigger, Slack Webhooks, or GitHub events.EXECUTIONS_DATA_PRUNE: Set totrueto automatically delete historical execution records, preventing local storage volume exhaustion over time.EXECUTIONS_DATA_MAX_AGE: Defines record retention duration in hours. Retaining logs for 168 hours (7 days) Balances debugging flexibility against database size limits.
4. Setting Up Caddy Reverse Proxy for Automated HTTPS Certificates
Automating TLS certificate retrieval and WebSocket proxying ensures safe web communication without manually managing certbot renewal scripts. Caddy reverse proxy handles automated Let's Encrypt certificates natively while requiring minimal configuration syntax.
Append a Caddy container service directly to your existing docker-compose.yml file:
caddy:
image: caddy:2-alpine
restart: always
ports:
- "80:80"
- "443:443"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile
- caddy_data:/data
- caddy_config:/config
depends_on:
- n8n`
Add caddy_data: and caddy_config: to your top-level volumes: array inside docker-compose.yml.
Next, construct a Caddyfile in your configuration directory:
n8n.example.com {
reverse_proxy n8n:5678 {
flush_interval -1
}
}
The flush_interval -1 setting is crucial for real-time visual canvas rendering. It instructs Caddy to immediately pass Server-Sent Events (SSE) and WebSocket frames back to the client interface, allowing workflow execution nodes to reflect state changes on screen without stream buffering delays.
Spin up your container stack using Docker Compose v2.29:
docker compose up -d
Inspect startup container logs using docker compose logs -f to verify that PostgreSQL initialized successfully, n8n executed its migrations, and Caddy bound port 443 with valid SSL certificates.
5. Self Hosted n8n Maintenance vs Low Cost n8n Hosting
Once you figure out how to install n8n on your server, ongoing maintenance becomes your responsibility. Operating self hosted n8n infrastructure requires regular maintenance tasks that consume technical resources:
- Updating n8n image tags, running database migration scripts, and checking release notes for breaking node changes.
- Monitoring system memory consumption during memory-intensive processing tasks like binary data transformations or high-frequency HTTP requests.
- Configuring off-site volume snapshots to guard against virtual machine disk corruption or host provider outages.
- Securing base operating system updates against vulnerabilities in packages like OpenSSL, systemd, and glibc.
For individuals and growing teams seeking best n8n hosting without technical overhead, managing individual infrastructure instances quickly becomes inefficient. Utilizing low cost n8n hosting through n8nautomation.cloud provides access to fully dedicated instances running official n8n Community Edition starting at $4/month.
Choosing dedicated n8n managed hosting delivers critical platform advantages over self-managed VPS servers:
- Zero DevOps Burden: Instant setup with automated application patching, zero server configuration, and 24/7 uptime monitoring.
- Pre-Configured Backups: Automatic state backups ensure workflow configurations and system data remain protected against loss.
- Custom Domain Flexibility: Deploy instantly with custom subdomains (such as
yourname.n8nautomation.cloud) while retaining full flexibility to switch to custom domains whenever needed. - Complete System Access: Access granular execution logs directly through our intuitive management interface, giving advanced users detailed runtime visibility without manual terminal SSH connections.
6. Migrating Workflows to n8n Managed Hosting in Seconds
If you currently operate a self hosted n8n instance on Ubuntu or AWS EC2 and want to transition to fully managed n8n hosting, moving your workflows does not require tedious manual exporter scripts or raw database dumps.
At n8nautomation.cloud, users access a streamlined n8n migration tool designed for swift workflow transfers between servers:
- Generate a Public API key inside your existing self hosted n8n user settings panel.
- Launch your dedicated instance on n8nautomation.cloud and locate the migration tool within your dashboard settings.
- Input your source server URL alongside the API key into the migration form.
- Select destination parameters and launch the automated migration routine.
The migration engine processes workflow node structures, connections, code transforms, and trigger triggers, completing data transfers across instances within seconds. For security reasons, authentication credentials are not transferred across public API payloads—allowing you to safely reconnect sensitive OAuth tokens and database passwords within your new instance environment.
By leveraging structured hosting services, developers focus entirely on building high-value automation logic using 400+ built-in integrations and community nodes while avoiding infrastructure maintenance tasks entirely.
Related Posts
How to Install n8n v1.85 via Docker Compose vs Low Cost n8n Hosting
Learn how to install n8n v1.85 using Docker Compose on Ubuntu, manage SSL certificates, or opt for low cost n8n hosting starting at $4/month.
Solving n8n ERR_OUT_OF_MEMORY Crashes in v1.82 Data Pipelines
Learn how to fix n8n ERR_OUT_OF_MEMORY crashes in v1.82 pipelines using proper memory tuning, stream batching, and low cost n8n hosting options.
Automating Shopify Order Fulfillment with n8n Code Node v2
Learn how to process Shopify webhooks, verify HMAC signatures, and route order fulfillments using n8n Code Node v2 and managed n8n hosting options.