mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
📚 Add 🐳 Docker Compose example for 🐘 PostgresQL
This commit is contained in:
parent
c339dfd5d6
commit
53c82c1e90
6
docker/compose/withPostgres/.env
Normal file
6
docker/compose/withPostgres/.env
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
POSTGRES_USER=adminuser
|
||||||
|
POSTGRES_PASSWORD=JvsjjAYg12FJ90sdCBdsh322V
|
||||||
|
POSTGRES_DB=n8n
|
||||||
|
|
||||||
|
POSTGRES_NON_ROOT_USER=n8nuser
|
||||||
|
POSTGRES_NON_ROOT_PASSWORD=PLsQ8vHGShwDFdmSssb
|
26
docker/compose/withPostgres/README.md
Normal file
26
docker/compose/withPostgres/README.md
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
# n8n with PostgreSQL
|
||||||
|
|
||||||
|
Starts n8n with PostgreSQL as database.
|
||||||
|
|
||||||
|
|
||||||
|
## Start
|
||||||
|
|
||||||
|
To start n8n with PostgreSQL simply start docker-compose by executing the following
|
||||||
|
command in the current folder.
|
||||||
|
|
||||||
|
|
||||||
|
**IMPORTANT:** But before you do that change the default users and passwords in the [`.env`](.env) file!
|
||||||
|
|
||||||
|
```
|
||||||
|
docker-compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
To stop it execute:
|
||||||
|
|
||||||
|
```
|
||||||
|
docker-compose stop
|
||||||
|
```
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
The default name of the database, user and password for PostgreSQL can be changed in the [`.env`](.env) file in the current directory.
|
35
docker/compose/withPostgres/docker-compose.yml
Normal file
35
docker/compose/withPostgres/docker-compose.yml
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
version: '3.1'
|
||||||
|
|
||||||
|
services:
|
||||||
|
|
||||||
|
postgres:
|
||||||
|
image: postgres:11
|
||||||
|
restart: always
|
||||||
|
environment:
|
||||||
|
- POSTGRES_USER
|
||||||
|
- POSTGRES_PASSWORD
|
||||||
|
- POSTGRES_DB
|
||||||
|
- POSTGRES_NON_ROOT_USER
|
||||||
|
- POSTGRES_NON_ROOT_PASSWORD
|
||||||
|
volumes:
|
||||||
|
- ./init-data.sh:/docker-entrypoint-initdb.d/init-data.sh
|
||||||
|
|
||||||
|
n8n:
|
||||||
|
image: n8nio/n8n
|
||||||
|
restart: always
|
||||||
|
environment:
|
||||||
|
- DB_TYPE=postgresdb
|
||||||
|
- DB_POSTGRESDB_HOST=postgres
|
||||||
|
- DB_POSTGRESDB_PORT=5432
|
||||||
|
- DB_POSTGRESDB_DATABASE=${POSTGRES_DB}
|
||||||
|
- DB_POSTGRESDB_USER=${POSTGRES_NON_ROOT_USER}
|
||||||
|
- DB_POSTGRESDB_PASSWORD=${POSTGRES_NON_ROOT_PASSWORD}
|
||||||
|
ports:
|
||||||
|
- 5678:5678
|
||||||
|
links:
|
||||||
|
- postgres
|
||||||
|
volumes:
|
||||||
|
- ~/.n8n:/root/.n8n
|
||||||
|
# Wait 5 seconds to start n8n to make sure that PostgreSQL is ready
|
||||||
|
# when n8n tries to connect to it
|
||||||
|
command: /bin/sh -c "sleep 5; n8n start"
|
12
docker/compose/withPostgres/init-data.sh
Executable file
12
docker/compose/withPostgres/init-data.sh
Executable file
|
@ -0,0 +1,12 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set -e;
|
||||||
|
|
||||||
|
|
||||||
|
if [ -n "${POSTGRES_NON_ROOT_USER:-}" ] && [ -n "${POSTGRES_NON_ROOT_PASSWORD:-}" ]; then
|
||||||
|
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
|
||||||
|
CREATE USER ${POSTGRES_NON_ROOT_USER} WITH PASSWORD '${POSTGRES_NON_ROOT_PASSWORD}';
|
||||||
|
GRANT ALL PRIVILEGES ON DATABASE ${POSTGRES_DB} TO ${POSTGRES_NON_ROOT_USER};
|
||||||
|
EOSQL
|
||||||
|
else
|
||||||
|
echo "SETUP INFO: No Environment variables given!"
|
||||||
|
fi
|
|
@ -136,14 +136,16 @@ docker run -it --rm \
|
||||||
-e DB_TYPE=postgresdb \
|
-e DB_TYPE=postgresdb \
|
||||||
-e DB_POSTGRESDB_DATABASE=<POSTGRES_DATABASE> \
|
-e DB_POSTGRESDB_DATABASE=<POSTGRES_DATABASE> \
|
||||||
-e DB_POSTGRESDB_HOST=<POSTGRES_HOST> \
|
-e DB_POSTGRESDB_HOST=<POSTGRES_HOST> \
|
||||||
-e DB_POSTGRESDB_PASSWORD=<POSTGRES_PASSWORD> \
|
|
||||||
-e DB_POSTGRESDB_PORT=<POSTGRES_PORT> \
|
-e DB_POSTGRESDB_PORT=<POSTGRES_PORT> \
|
||||||
-e DB_POSTGRESDB_USER=<POSTGRES_USER> \
|
-e DB_POSTGRESDB_USER=<POSTGRES_USER> \
|
||||||
|
-e DB_POSTGRESDB_PASSWORD=<POSTGRES_PASSWORD> \
|
||||||
-v ~/.n8n:/root/.n8n \
|
-v ~/.n8n:/root/.n8n \
|
||||||
n8nio/n8n \
|
n8nio/n8n \
|
||||||
n8n start
|
n8n start
|
||||||
```
|
```
|
||||||
|
|
||||||
|
A full working setup with docker-compose can be found [here](../../compose/withPostgres/README.md)
|
||||||
|
|
||||||
|
|
||||||
## Passing Senstive Data via File
|
## Passing Senstive Data via File
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue