Where do you put the postgres server details when running in docker?

So after trying n8n out with the default sqlitedb, I’m trying to get it started using postgres for the back end, using
https://docs.n8n.io/reference/server-setup.html#_6-create-env-file
and
https://docs.n8n.io/reference/data/database.html#postgresdb
But it’s not obvious where to put the exported variables - adding them to a script that does a basic “docker run” doesn’t work. Neither does putting them in a file: ~/.n8n/.env
right now I am doing this:

#!/bin/bash
# 20200927
export DB_TYPE=postgresdb
export DB_POSTGRESDB_DATABASE=n8n
export DB_POSTGRESDB_HOST=psql
export DB_POSTGRESDB_PORT=5432
export DB_POSTGRESDB_USER=n8n
export DB_POSTGRESDB_PASSWORD=n8n
# export DB_POSTGRESDB_SCHEMA=n8n

docker run -it --rm \
--name n8n \
-p 5678:5678 \
-v ~/.n8n:/root/.n8n \
n8nio/n8n:latest

and then using nginx in front of it.

What am I missing?
Thanks,
Sean

You can find a full example which starts n8n via docker-compose with Postgres here:

Apart from that can the you use the default docker-syntax to set environment variables -e NAME=VALUE as described here in the docker documentation:

Here also a full example for a one-liner with all variables set:

I do not have an example ready with nginx in front of it. But you can combine the above examples with any other docker-example which puts nginx in front of X and you should the be able to get it up and running.

Apart from that do I strongly recommend you to follow our server-setup guide. It does not use nginx but but traefik and takes care of everything:
https://docs.n8n.io/reference/server-setup.html

Hope that helps!

Great! :slight_smile:
That makes more sense.
I shall give it a go tomorrow.
Thanks.

So that works fine with the -e docker options. :slight_smile:
Although it isn’t necessary to add in the schema option for the psql connection. TBH, I’ve never had to use that in 20+ years of being a sysadmin.
(and the machine it’s on right now is actually running apache, not nginx)
I might give traefik a go if I move it to its own container.
For my setup it’s more likely that any external webhooks would be coming via haproxy, so I’ll look at that soon.

Thanks,
Sean