-
Notifications
You must be signed in to change notification settings - Fork 41.6k
Closed as not planned
Closed as not planned
Copy link
Labels
status: declinedA suggestion or change that we don't feel we should currently applyA suggestion or change that we don't feel we should currently apply
Description
Hi I'm using spring-boot-docker-compose to have a postgres database start when the app starts but getting error at startup
java.lang.IllegalStateException: No POSTGRES_PASSWORD defined
This is due to PostgresEnvironment extracting environment variables but assuming there is a POSTGRES_PASSWORD environment variable.
I am using the supported POSTGRES_PASSWORD_FILE environment variable instead, which is how you can keep secrets out of version control.
Steps to reproduce
- Configure pom.xml
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-docker-compose</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
...- Add docker-compose.yml in the root project folder
version: '3.8'
services:
db:
image: postgres:14.5
restart: always
environment:
POSTGRES_DB: mydb
POSTGRES_USER: myuser
POSTGRES_PASSWORD_FILE: /run/secrets/db_password
ports:
- 5432:5432
secrets:
- db_password
volumes:
- postgres-data:/var/lib/postgresql/data
volumes:
postgres-data:
secrets:
db_password:
file: src/main/resources/postgres_password.txt- Save a secrets file
- Save the postgres password in the Spring Boot app under
src/main/resources/postgres_password.txt
- Save the postgres password in the Spring Boot app under
- Run the app
- Expecting the app to start but instead getting
java.lang.IllegalStateException: No POSTGRES_PASSWORD defined
Running docker compose up works fine and the container starts.
Spring Boot version: 3.1.1
Java version: openjdk 17.0.8.1
Metadata
Metadata
Assignees
Labels
status: declinedA suggestion or change that we don't feel we should currently applyA suggestion or change that we don't feel we should currently apply