Chapter 02

データベース起動

Thirosue
Thirosue
2021.05.16に更新

データベース起動

ローカルPCでpostgresを起動させます。

データベース設定(コンテナ)ファイル生成

発行されたSQLが表示されるようにする
以下の内容で、コンテナ設定ファイルを作成します。

docker-compose.yml
version: "3.7"
services:
  db:
    container_name: postgres
    image: postgres:13
    ports:
      - "5432:5432"
    # Make postgres logs. More information about logging, see official documentation: https://www.postgresql.org/docs/11/runtime-config-logging.html
    command: postgres -c log_destination=stderr -c log_statement=all -c log_connections=on -c log_disconnections=on
    environment:
      - POSTGRES_PASSWORD=postgres
    logging:
      options:
        max-size: "10k"
        max-file: "5"

ヒアドキュメントを利用して、作成しましょう。

cat <<EOF > docker-compose.yml
version: "3.7"
services:
  db:
    container_name: postgres
    image: postgres:13
    ports:
      - "5432:5432"
    # Make postgres logs. More information about logging, see official documentation: https://www.postgresql.org/docs/11/runtime-config-logging.html
    command: postgres -c log_destination=stderr -c log_statement=all -c log_connections=on -c log_disconnections=on
    environment:
      - POSTGRES_PASSWORD=postgres
    logging:
      options:
        max-size: "10k"
        max-file: "5"
EOF

データベース起動

docker-compose up -d

SQLログを表示する

本チュートリアルでは発行したSQLを確認していきます。
発行されたクエリが気になる方は、以下コマンドでログを確認してください。

docker logs -f postgres