This repository provides a Docker Compose configuration for running n8n (a workflow automation tool) with a PostgreSQL database backend.
This setup allows you to self-host n8n easily using Docker, providing a persistent database storage solution with PostgreSQL. It includes basic authentication and is configured for easy deployment and management.
- Docker installed on your system.
- Docker Compose installed on your system.
-
Clone the repository (if you haven't already):
git clone https://github.com/themahani/n8n.git cd n8n
-
Create a
.env
file: Copy the example environment file:cp .env.example .env
-
Configure Environment Variables: Edit the
.env
file and replace the placeholder values with your desired settings. See the Configuration section below for details.
The .env
file contains the necessary configuration variables for the services:
POSTGRES_DB
: The name of the PostgreSQL database for n8n.POSTGRES_USER
: The username for the PostgreSQL database.POSTGRES_PASSWORD
: The password for the PostgreSQL database user. Choose a strong password.N8N_BASIC_AUTH_USER
: The username for n8n's basic authentication (login).N8N_BASIC_AUTH_PASSWORD
: The password for n8n's basic authentication. Choose a strong password.TIMEZONE
: Your local timezone (e.g.,America/Edmonton
). Find your timezone here.
Example .env
:
POSTGRES_DB=n8n_database
POSTGRES_USER=n8n_user
POSTGRES_PASSWORD=supersecretpassword123
N8N_BASIC_AUTH_USER=admin
N8N_BASIC_AUTH_PASSWORD=anothersecretpassword456
TIMEZONE=America/New_York
-
Start the services: Navigate to the directory containing the
docker-compose.yaml
file and run:docker compose up -d
This command will build (if necessary) and start the
postgres
andn8n
services in detached mode (-d
). -
Access n8n: Once the containers are running, you can access the n8n web interface by navigating to
http://localhost:5678
in your web browser. You will be prompted to log in using theN8N_BASIC_AUTH_USER
andN8N_BASIC_AUTH_PASSWORD
you set in the.env
file. -
Stop the services: To stop the running containers:
docker compose down
-
Stop and remove volumes (use with caution): To stop the containers and remove the associated data volumes (PostgreSQL data, n8n data):
docker compose down -v
Warning: This will delete all your n8n workflows and PostgreSQL data unless you have backups.
- PostgreSQL Data: Stored in a Docker volume named
postgres_storage
. - n8n Data: Stored in a Docker volume named
n8n_storage
(mounted at/home/node/.n8n
inside the container). - Backup/Import: The configuration includes an
n8n-import
service and mounts./n8n/backup
to/backup
inside the containers, suggesting a potential workflow for backing up and restoring credentials and workflows. - Shared Data: A local directory
./shared
is mounted to/data/shared
inside the n8n container, allowing file sharing between the host and the container.
After starting the services and logging in, you can begin creating and managing your automation workflows through the n8n web interface. Refer to the official n8n documentation for guides and examples.