266 words
1 minute
Install n8n
Prerequisites
Steps
- Prepare docker-compose.yml
- Start with db
docker-compose.yml services:n8n:image: docker.n8n.io/n8nio/n8ncontainer_name: n8nrestart: always # Added to ensure n8n restarts if it crashesports:- "5678:5678"environment:- DB_TYPE=postgresdb- DB_POSTGRESDB_DATABASE=n8n_database- DB_POSTGRESDB_HOST=postgres # Hostname of the postgres service- DB_POSTGRESDB_PORT=5432- DB_POSTGRESDB_USER=n8n_user # Changed to a specific user for n8n- DB_POSTGRESDB_PASSWORD=<Your Database Password> # Use a strong password!# If you're using a self-signed SSL certificate for your Postgres, uncomment and set the following:# - NODE_TLS_REJECT_UNAUTHORIZED=0volumes:- n8n_data:/home/node/.n8ndepends_on:- postgres # n8n depends on postgres being upnetworks:- n8n_network # Assign to a custom networkpostgres:image: postgrescontainer_name: n8n_postgresrestart: alwaysenvironment:POSTGRES_DB: n8n_databasePOSTGRES_USER: n8n_user # Should match DB_POSTGRESDB_USER in n8n servicePOSTGRES_PASSWORD: <Your Database Password> # Should match DB_POSTGRESDB_PASSWORD in n8n servicePGDATA: /var/lib/postgresql/data/pgdata # Optional: Specify a sub-directory for datavolumes:- postgres_data:/var/lib/postgresql/data # Persist PostgreSQL datanetworks:- n8n_network # Assign to the same custom network as n8nvolumes:n8n_data:postgres_data: # Define the volume for PostgreSQL datanetworks:n8n_network: # Define a custom bridge networkdriver: bridge- Start without database (already have one)
docker-compose.yml services:n8n:image: docker.n8n.io/n8nio/n8ncontainer_name: n8nports:- "5678:5678"environment:- DB_TYPE=postgresdb- DB_POSTGRESDB_DATABASE=n8n_database- DB_POSTGRESDB_HOST=localhost- DB_POSTGRESDB_PORT=5432- DB_POSTGRESDB_USER=postgres- DB_POSTGRESDB_PASSWORD=<Your Database Password># If you're using a self-signed SSL certificate for your Postgres, uncomment and set the following:# - NODE_TLS_REJECT_UNAUTHORIZED=0volumes:- n8n_data:/home/node/.n8nnetwork_mode: hostvolumes:n8n_data:# You can specify a driver here if needed, e.g., for network storage:# driver: local - Start services
Terminal window docker compose up -d
CAUTIONYou shouldn’t put secrets in the file, as I did. It’s just for example.
References
Install n8n
https://slimaeus.github.io/posts/intall-n8n/