application.propertiesのDB指定
application.propertiesでDBを指定する際は
Dokerで指定しているサービス名となる。
#spring.datasource.driver-class-name=org.postgresql.Driver
#spring.datasource.url=jdbc:postgresql://localhost:5432/example
#spring.datasource.username=postgres
#spring.datasource.password=postgres
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://db:5432/example
spring.datasource.username=postgres
spring.datasource.password=postgres
spring.datasource.url=jdbc:postgresql://db:5432/example
dbとはdocker-compose.ymlのDBのサービス名とすること。
services:
# Javaの設定情報
java:
# コンテナ名
container_name: springjar
build: ./java
ports:
- "8080:8080"
# local参照先:コンテナ展開先
volumes:
- ./build/libs:/app
# コンテナ内のディレクトリ定義
working_dir: /app
tty: true
db:
container_name: spring_list_post
build: ./image/postgres
restart: always
ports:
- "5432:5432"
volumes:
- ./postgres/init:/docker-entrypoint-initdb.d
environment:
POSTGRES_USER: "postgres"
POSTGRES_PASSWORD: "postgres"