docker-composeでPostgreSQLを使う場合のメモ。Docker HubにあるPostgreSQL公式ページは以下になります。

サンプル

services:
  postgres:
    image: postgres:17
    container_name: postgres
    build: ./image/postgres
    restart: always
    ports:
      - 5432:5432
    volumes:
      - ./postgres/data:/var/lib/postgresql/data
      - ./postgres/init:/docker-entrypoint-initdb.d
    environment:
      POSTGRES_USER: "postgres"
      POSTGRES_PASSWORD: "postgres"
      POSTGRES_DB: sampledb