0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

DockerでSpring Bootを動かす際のapplication.propertiesのDB指定

Posted at

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
                  :point_up:

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"
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?