Content
You are here:
docker secrets not working for environment variable DATABASE_URL
Hey all,
I'm trying to deploy a compose stack (in portainer) with a postgres database and openproject. When I enter the database url including the credeantials directly via the environment variable DATABASE_URL the openproject service connects to it.
However, when I use docker secrets instead of entering the DATABASE_URL environment directly, it doesnt work. The logs of the openproject container show that no database was detected and a new one is created.
Any insight any of you might have is greatly appreciated.
Regards,
André
The compose file looks like this:
version: "3.9"
services:
db:
image: postgres:13 # Works only with Postgres version 13
container_name: openproject-db
hostname: openproject-db
dns:
- X.X.X.X
- Y.Y.Y.Y
mem_limit: 512m
cpu_shares: 768
security_opt:
- no-new-privileges:true
healthcheck:
test: ["CMD", "pg_isready", "-q", "-d", "openproject", "-U", "openprojectuser"]
timeout: 45s
interval: 10s
retries: 10
volumes:
- /mnt/dockerData/openproject/db:/var/lib/postgresql/data:rw
environment:
POSTGRES_DB__FILE: /run/secrets/secrets_openproject_db
POSTGRES_USER__FILE: /run/secrets/secrets_openproject_db_user
POSTGRES_PASSWORD__FILE: /run/secrets/secrets_openproject_db_password
secrets:
- secrets_openproject_db
- secrets_openproject_db_user
- secrets_openproject_db_password
stop_grace_period: 3s
restart: always
cache:
image: memcached:latest
container_name: OpenProject-CACHE
hostname: cache
dns:
- 94.140.14.140
- 176.9.93.198
mem_limit: 512m
cpu_shares: 768
security_opt:
- no-new-privileges:true
read_only: true
restart: always
openproject:
image: openproject/community:13
container_name: OpenProject
hostname: openproject
dns:
- 94.140.14.140
- 176.9.93.198
mem_limit: 4g
cpu_shares: 768
security_opt:
- no-new-privileges:true
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:80/health_checks/default"]
interval: 10s
timeout: 3s
retries: 3
start_period: 30s
ports:
- 5122:80
environment:
OPENPROJECT_HTTPS: true
OPENPROJECT_HOST__NAME: pm.riegera.de
OPENPROJECT_HSTS: true
RAILS_CACHE_STORE: memcache
OPENPROJECT_CACHE__MEMCACHE__SERVER: cache:11211
OPENPROJECT_RAILS__RELATIVE__URL__ROOT:
#DATABASE_URL: postgres://[dbuser]:[dbpassword]@openproject-db:5432/openproject ## <- this does work
DATABASE_URL__FILE: /run/secrets/secrets_openproject_db_url ## <- this doesnt work
RAILS_MIN_THREADS: 4
RAILS_MAX_THREADS: 16
IMAP_ENABLED: false
secrets:
- secrets_openproject_db_url
volumes:
- /mnt/dockerData/openproject/data/pgdata:/var/openproject/pgdata:rw
- /mnt/dockerData/openproject/data/assets:/var/openproject/assets:rw
restart: always
secrets:
secrets_openproject_db:
file: /mnt/dockerData/openproject/secrets_openproject_db.txt
secrets_openproject_db_password:
file: /mnt/dockerData/openproject/secrets_openproject_db_password.txt
secrets_openproject_db_url:
file: /mnt/dockerData/openproject/secrets_openproject_db_url.txt
secrets_openproject_db_user:
file: /mnt/dockerData/openproject/secrets_openproject_db_user.txt