More than ever, task automation has become an essential lever for increasing productivity, particularly in Linux environments where workflow management can quickly become complex. n8n presents itself as the ideal flexible open-source solution for connecting APIs, orchestrating webhooks, and managing complex integrations without reinventing the wheel. Docker, for its part, simplifies deployment by isolating the runtime environment, ensuring stable and portable operation, regardless of the underlying Linux system. This detailed guide provides a step-by-step guide to deploying n8n with Docker on a Linux server, whether a dedicated machine or a cloud environment, leveraging robust tools like PostgreSQL for the database and Nginx as a secure reverse proxy. This tutorial is aimed at both system administrators looking to industrialize their automation solutions and Linux enthusiasts eager to explore the potential of Node.js in containerized environments. Essential Prerequisites for Installing n8n with Docker on a Linux System
Before beginning deployment, it’s crucial to prepare a suitable environment where each component can work seamlessly. The Linux server must be stable, typically Debian or Ubuntu, known for their robustness and broad compatibility with Docker and its related tools. It’s imperative that Docker and Docker Compose are installed, as they orchestrate the launch of the containers that will host n8n and its dependencies.
To secure your n8n instance, a reverse proxy such as Nginx or Traefik is recommended. This will allow you to add an SSL/TLS certificate, often managed for free via Let’s Encrypt. This level of security is essential when exposing webhooks or APIs to the internet, ensuring the confidentiality and integrity of exchanges. In production, using a PostgreSQL database is preferable to the native SQLite option, as it ensures better scalability and more efficient handling of numerous queries. Here is the list of essential prerequisites:
Up-to-date Linux server
(Debian 11+, Ubuntu 22.04+ recommended)
- Docker and Docker Compose installed with compatible versions (Docker 20.10+, Compose 2.x)
- Reverse proxy installed (Nginx or Traefik recommended)
- Domain name pointing to the server to facilitate access and SSL configuration
- PostgreSQL configured via Docker to manage the n8n database
- Suitable network configuration : ports 80, 443 (HTTP/S), and 5678 (n8n) open and redirected if necessary
- Any Linux beginner will benefit from understanding what these elements represent: Docker encapsulates applications in lightweight containers, isolated from the host system, while a reverse proxy like Nginx redirects and secures incoming access to n8n. PostgreSQL is a powerful relational database that should be favored for a production instance, due to its robustness and compatibility with the Node.js framework, on which n8n is based. Configuring the Docker environment and customizing n8n with Docker Compose on Linux
The magic of deploying n8n on Linux lies in the ease of use of Docker Compose. This YAML file describes all the containers and their interactions in a readable and editable format. The initial configuration consists of creating a dedicated n8n tree, then defining two essential files:
.env
for environment variables, and docker-compose.yml to orchestrate services. An often overlooked aspect is the segregation of persistent data. Three local folders must be created: one for PostgreSQL data, one for files generated by n8n, and a final one for temporary or swap files. These directories will be mounted in the respective containers, preventing data loss in the event of a reboot or update. Example of creating directories: mkdir -p /opt/docker-compose/n8n/{postgresql,n8n_data,n8n_files}
chmod 777 /opt/docker-compose/n8n/n8n_data (necessary to avoid permission errors)
The
- .env
- file contains key variables:
N8N_HOST : hostname that the interface will display and use to generate URLs N8N_WEBHOOK_URL
- : publicly accessible URL for webhooks to work properly POSTGRES_DB
- , POSTGRES_USER
- ,POSTGRES_PASSWORD : PostgreSQL database connection informationN8N_GENERIC_TIMEZONE : time zone, affecting workflow execution The
- docker-compose.yml includes two main services:
postgres : based on The official PostgreSQL image with environment variable settings, persistence volumes, and health checks n8n
- : Official n8n Docker image, environment variable configuration to connect the application to the database, port management, volume to persist data and files, and PostgreSQL health dependency By configuring using these two files, you create an automated, reproducible, and easily modifiable environment. This is the combined strength of open source software, Docker, and Linux. This method also protects you against dependency errors or incompatibilities between versions.
- https://www.youtube.com/watch?v=NAzpMf50auI Starting and managing Docker containers for n8n on a Linux system
Once the environment is ready, you must ensure that the permissions on the mounted folders are correct to prevent the n8n container from having trouble writing its files. In most cases, a chmod 777 setting on the folder containing n8n’s data is necessary, although this approach is permissive and requires a thorough understanding of the associated risks. Launching the containers with the following command allows you to initiate and deploy background services:sudo docker compose up -d
sudo docker compose ps
to see the list of active containers and their status
sudo docker compose logs -f
- to view the output logs in real time, essential in case of problems
The PostgreSQL container must be in a “healthy” state so that n8n can connect properly and start without errors. The logs will display messages such as:
- “Editor is now accessible via: https://n8n.it-connect.local” This message confirms that the service is operational and ready for use through port 5678, accessible from your browser via the configured domain name. Using a log manager greatly simplifies diagnostics when deploying complex solutions based on Node.js, PostgreSQL databases, and middleware.
- Configure an Nginx reverse proxy to secure and expose n8n over HTTPS on Linux A reverse proxy is a fundamental building block for securing access to n8n, especially if you use webhooks or expose your automation over the internet. Nginx is an optimal choice on Linux due to its lightweight, reliability, and ease of configuration. Instead of directly exposing Docker port 5678, Nginx acts as an intermediary, allowing you to apply an SSL/TLS certificate and manage essential redirects and HTTP headers. Here are the key steps:
Install Nginx via the package manager, for example, sudo apt install nginx on Debian/Ubuntu.
Create a directory to store the self-signed or Let’s Encrypt-generated SSL certificate.
Generate a certificate with OpenSSL (or via Certbot for Let’s Encrypt):
sudo openssl req -x509 -nodes -days 365 -newkey rsa:4096 -keyout /etc/nginx/ssl/n8n.key -out /etc/nginx/ssl/n8n.crt
The Nginx configuration must include two server blocks:
A block listening on port 80, which will perform a 301 redirect to HTTPS. An HTTPS block, with a certificate, TLS 1.2 and 1.3 protocol support, and proxy_pass configuration on
- http://127.0.0.1:5678
where n8n runs.The essential configuration file will look like this (domain name to be adapted): - Nginx configuration snippet:
- server {
listen 80;
server_name n8n.example.com;
- return 301 https://$server_name$request_uri;
- }
server {listen 443 ssl http2;
server_name n8n.example.com;
ssl_certificate /etc/nginx/ssl/n8n.crt;
nserver {n listen 80;n server_name n8n.example.com;n return 301 https://$server_name$request_uri;n}nnserver {n listen 443 ssl http2;n server_name n8n.example.com;nn ssl_certificate /etc/nginx/ssl/n8n.crt;n ssl_certificate_key /etc/nginx/ssl/n8n.key;n ssl_protocols TLSv1.2 TLSv1.3;n ssl_prefer_server_ciphers off;n ssl_session_cache shared:SSL:10m;n ssl_session_timeout 10m;nn location / {n proxy_pass http://127.0.0.1:5678;n proxy_http_version 1.1;n proxy_set_header Upgrade $http_upgrade;n proxy_set_header Connection 'upgrade';n proxy_set_header Host $host;n proxy_set_header X-Real-IP $remote_addr;n proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;n proxy_set_header X-Forwarded-Proto $scheme;nn proxy_buffering off;n proxy_read_timeout 300s;n }n}n“} –>
ssl_certificate_key /etc/nginx/ssl/n8n.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers off;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
rental / {
proxy_pass http://127.0.0.1:5678;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_bufferingoff;
proxy_read_timeout 300s;
}
}
Activating this site via a symbolic link in
/etc/nginx/sites-enabled/
then reloading Nginx is essential:
sudo ln -s /etc/nginx/sites-available/n8n.example.com /etc/nginx/sites-enabled/
sudo systemctl reload nginx
By accessing https://n8n.example.com, you will see the n8n administration interface, protected by HTTPS. An SSL certificate warning may occur if the certificate is self-signed, but this can be fixed via a recognized CA.
Getting Started with n8n: Managing Workflows, Webhooks, and API Integrations on Linux
Once n8n is installed and accessible, configuring workflows allows you to fully leverage automation. n8n is built on Node.js and offers native support for hundreds of services via their APIs, simplifying complex automation chains. Key concepts include:
Workflows : Automated task sequences that can include scripts, API calls, and various triggers. Webhooks
: HTTP entry points for triggering a workflow externally, crucial for reacting to external events.Integrations
: Native connectors for MySQL, PostgreSQL, Redis, and many others, facilitating data interconnection.
n8n also offers an intuitive graphical interface and ready-to-use templates, accessible via GitHub or the official website, speeding up the process, even for novices. Using Redis as an intermediate cache is recommended to improve queue management in large production workflows.
The synergy between Docker, Linux, and n8n simplifies traditionally complex deployments. This modular architecture facilitates updates and debugging, and offers controlled scalability to support the growth of automation applications.