This sample shows how to get a n8n app up using PostgreSQL as a database and running with Defang. We based it in part on the original sample from the n8n team, but we have adapted it to be consistent with the way our other samples are configured.
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate with your cloud provider account
- (Optional for local development) Docker CLI
To run the application locally for development, use the development compose file:
docker compose -f compose.dev.yaml upThis will:
- Start PostgreSQL with volume persistence for local development
- Expose PostgreSQL on port 5432 for direct access if needed
- Start n8n on port 5678 with volume persistence
You can access n8n at http://localhost:5678 once the containers are running.
For this sample, you will need to provide the following configuration. Note that if you are using the 1-click deploy option, you can set these values as secrets in your GitHub repository and the action will automatically deploy them for you.
The password for your Postgres database. You need to set this before deploying for the first time.
You can easily set this to a random string using defang config set POSTGRES_PASSWORD --random
The encryption key for your n8n instance. This is used to encrypt sensitive data in the database.
You can easily set this to a random string using defang config set N8N_ENCRYPTION_KEY --random
Set to true to enable SSL. Set to false to disable SSL.
Set to true to reject unauthorized certificates. Set to false to accept unauthorized certificates. Counterintuitive, but leave this as true to disable SSL (required for local dev and playground).
Note
Download Defang CLI
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose upIf you want to deploy to your own cloud account, you can use Defang BYOC.
Warning
Extended deployment time: This sample creates a managed PostgreSQL database which may take upwards of 20 minutes to provision on first deployment. Subsequent deployments are much faster (2-5 minutes).
Title: n8n
Short Description: A n8n app running on Defang.
Tags: n8n, PostgreSQL, Docker
Languages: Docker, Shell
