I'm trying to set the environment variables for DB password for MySQL container and spring boot application which is commonly declared in the docker secrets.
echo "db_secured_password" | docker secret create secret -
here are the configuration files :
spring boot application's -> application.yml
db:
name: my-db
host: localhost
port: 3306
username: root
password: /run/secrets/db-root-password
spring:
application:
name: core-backend
datasource:
url: jdbc:mysql://${db.host}:${db.port}/${db.name}
username: ${db.username}
password: ${db.password}
used for docker stack in docker swarm mode -> docker-compose.yml
version: '3.1'
services:
mysql-db:
container_name: mysql-db
image: mysql:8.0.12
deploy:
restart_policy:
condition: on-failure
volumes:
- ./data/mysql:/var/lib/mysql
- ./conf/mysql/my.cnf:/etc/mysql/conf.d/my.cnf
environment:
- MYSQL_ROOT_PASSWORD=/run/secrets/db-root-password
- MYSQL_DATABASE=my_db
ports:
- "3306:3306"
secrets:
- db-root-password
spring-boot-app:
container_name: spring-boot-app
image: spring-boot-app:local
environment:
- DB_PASSWORD=/run/secrets/db-root-password
# Also tried adding with the file as property name
# - DB_PASSWORD_FILE=/run/secrets/db-root-password
ports:
- "8080:8080"
environment:
HOST_NAME: localhost
secrets:
- db-root-password
depends_on:
- mysql-db
secrets:
db-root-password:
external: true
I run the docker stack by using the following command:
docker stack deploy --with-auth-registry -c docker-compose.yml test-stack
I'm unable to get the value of the
db-root-password
property exactly in spring boot app. When I inspect the value ofdb-root-password
I get the value as/run/secrets/db-root-password
.
Is there something missing? If I want to override the value of Environment variable differently?