I have problem when I use docker compose and connection string i assign in ENV not recognize in spring application.yml
this is my docker-compose.yml
version: '3'
services:
mysqldb:
image: mysql:8.3.0
ports:
- "3307:3306"
environment:
MYSQL_ROOT_PASSWORD: 23012003aA@
MYSQL_DATABASE: checklist
restart: always
spring:
build:
context: ./back_end
dockerfile: Dockerfile
depends_on:
- mysqldb
environment:
- BE_PORT=9292
- DATASOURCE_URL=jdbc:mysql://localhost:3307/checklist
- DATASOURCE_USERNAME=root
- DATASOURCE_PASSWORD=123456789aA@
ports:
- "9292:9292"
this is my applicatiom.yml
spring:
datasource:
url: jdbc:mysql://localhost:3306/checklist?useSSL=false&createDatabaseIfNotExist=true
username: ${DATASOURCE_USERNAME}
password: ${DATASOURCE_PASSWORD}
jpa:
show-sql: false
hibernate:
ddl-auto: update
multipart:
max-file-size: 10MB
max-request-size: 10MB
why when I run it not recognize my connection string.
I try to paste connection string but it not work.
it run error about hibernate.
2
Answers
after I change follow us but my spring application return this error for me.
this is my application.yml
my docker compose for spring and mysql
You seems like not clearly about that how to associate spring applicatio with docker .
The reason you failed is that while both application and database might in same docker-compose , but they are in indenpent docker container , it means if you indicate the resouce url as localhost , it would request the application container itself not databasereousce container.
Fail Reason
The resource you define in docker should build in same network ,besides this put resouce and application all of them in same network , you can achieve this by define
network
like following code snippet Docker-compose. after above step , we should inject the resource variables into spring application.yamlAbove operation Step By Step like following:
application.yaml
Docker-compose