1
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】Unable to obtain connection from database: FATAL: ���[�U�["myuser"�̃p�X���[�h�F�؂Ɏ��s���܂���

Posted at

はじめに

DockerでPostgresコンテナを作成後、起動しようとするとPostgres接続時のパスワード認証エラーが発生しました。
遠回りして解決までに時間がかかってしまったので、備忘録としてまとめます。

問題

コンポーネントファイルを作成し、起動したところ下記のエラーが発生しました。

SQL State  : 28P01
Error Code : 0
Message    : FATAL: ���[�U�["myuser"�̃p�X���[�h�F�؂Ɏ��s���܂���

作成したコンポーネント

compose.yaml
services:
  postgres:
    image: 'postgres:latest'
    environment:
      - 'POSTGRES_DB=mydatabase'
      - 'POSTGRES_PASSWORD=secret'
      - 'POSTGRES_USER=myuser'
    ports:
      - '5432:5432'

原因

ローカル(私のPCのポート5432)がすでに使用されていたため。

# ホスト側でポート使用状況を確認
lsof -i :5432   # Mac/Linux
netstat -ano | findstr 5432  # Windows

確認したところ、確かに使用されていました。
image.png

解決方法

5432以外ののポート番号に変更する

compose.yaml
services:
  postgres:
    image: 'postgres:latest'
    environment:
      - 'POSTGRES_DB=mydatabase'
      - 'POSTGRES_PASSWORD=secret'
      - 'POSTGRES_USER=myuser'
    ports:
-      - '5432:5432'
+      - '5433:5432'

おわりに

最初はパスワードが登録されていないことが理由かとおもい、コンテナの内部に入ってpostgresのパスワードを登録したり、いろいろ試していました。
アプリケーションログだけでなく、コンテナ起動時のログも見る必要があると痛感しました。

1
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
1
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?