Deploy n8n on Coolify with PostgreSQL: A Step-by-step Guide


Introduction
The demand for workflow automation software and tools has greatly increased with the introduction of artificial intelligence agents. Technical teams can streamline workflows through AI agents in a matter of days.
n8n is one of the best workflow automation software options, featuring a vast collection of tools that empower users to easily create workflows on a canvas and connect to various external services. In this guide, I will demonstrate how you can deploy n8n software to Coolify as a self-hosting platform as a service.
Note: This guide assumes you have interacted with Coolify and set up your virtual private server with Coolify installed. If not, check out the Coolify docs for instructions on how to complete the setup.
Setting up the PostgreSQL database
Now that you have interacted with Coolify, it’s time to configure resources for running n8n. Firstly, create a new project from your Coolify dashboard, configure a new environment, or select the default production environment. You should now be able to add new resources as shown below:
Click on add new resource, under databases, select PostgreSQL and select PostgreSQL 16, which is the default version for Coolify:
After choosing the PostgreSQL version, you will see a configuration page for the PostgreSQL database as shown below. Leave everything as set and scroll down to initialization scripts:
In the initialization scripts section, click on add script and configure the script as shown below:
If you want a custom user, you can add the appropriate create user command, but for this step, I went with the default PostgreSQL user. Save the script and start the database. Sample output:
From the logs, mark the id icgkc08oosk4kkgskcwso4gg
which will be used to obtain the internal IP address for our PostgreSQL docker container for configuring our n8n
service.
Set up n8n Service with Docker
Add a new resource again, under the Docker-based section, select Docker image and save the official n8n Docker image as shown below:
Under network settings, change the default Ports Exposes from port 80 to 5678 and leave all defaults as shown below:
Save your changes and move to the Environment Variables section. Choose developer view and add the following environment variables
The N8N_ENCRPTION_KEY
can be generated using OpenSSL openssl rand -base64 32
. The DB_POSTGRESDB_PASSWORD
It is the password that was generated when creating the PostgreSQL database instance. The DB_POSTGRESDB_HOST
can be found from inspecting the coolify docker network and matching the key from the PostgreSQL database instance, as shown below:
From the output above, our DB_POSTGRESDB_HOST
Is the IPV4 address 10.0.1.21
. Now save the environment variables and deploy the application. The logs after a successful deployment will be as shown below:
Now visit the auto-generated domain from your application’s configuration on the browser, and you should see the n8n setup page, where you can now set up your n8n admin profile.
Note: When using the auto-generated domain, ensure to set N8N_SECURE_COOKIE
it to false to access n8n through the non-secure domain. Remove N8N_SECURE_COOKIE
the environment variable if you plan on setting up a secure domain through your domain provider for the n8n service. Thank you!
Subscribe to my newsletter
Read articles from Samuel Mugane directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Samuel Mugane
Samuel Mugane
Hello! I am Samuel Mugane, a Backend Developer living in Nairobi, Kenya. I am currently undertaking the ALX Software Engineering program. I enjoy building web apps using Django and Restful APIs using Django Rest Framework. I'm also a gaming enthusiast, I like first person shooting games like Crisis, COD and Tom Clancy's ghost recon. We can connect through my socials linked on my profile for project collaborations.