docker-compose 로 postgres + nginx + uwsgi 환경 구축과정에서 아래와 같은 오류 발생

```

postgres_1      | 2018-06-07 19:11:22.906 UTC [80] FATAL:  password authentication failed for user "db_user"

postgres_1      | 2018-06-07 19:11:22.906 UTC [80] DETAIL:  Password does not match for user "db_user".

postgres_1      | Connection matched pg_hba.conf line 95: "host all all all md5"

```

또는 `Role "db_user" does not exist.` 라는 오류도 같이 남.

uwsgi 대신 gunicorn 을 사용해서 미리 구축해둔 걸로 테스트해보면 잘됨. (설정파일 모두 동일한 걸로 맞춤)


Problem)

POSTGRES_XXX 환경변수는 모두 등록된 상태

컨테이너에서 postgres로 psql 명령어 실행 불가능 (Error: `Role "postgres" does not exist.`)

데이터베이스 조차 생성되지 않았음. (등록된 환경변수가 반영되지 않음)

  1. 이미 등록된 환경변수가 있는가?

  2. postgres의 role 이 사라진 이유?

사실 위 두 개만으로는 구글링해봐도 로컬에서 개발환경 구축 시 발생한 오류의 해결책이 많이 나옴.. (삽질의 연속)


Solution)

Is it possible that you generate the project more than once? In this scenario you get the error that you mention in your first post here. Here is what happens:


1. You generate the project the first time. The .env postgres file is populated with the random password

2. You run the docker-compose and the containers are created. The postgres container creates the database based on the .env file credentials

3. You "regenerate" the project with the same name, so the postgres .env file is populated with a **new** random password

4. You run docker-compose. Since the names of the containers are the same, docker will try to start them (**not create them from scratch** i.e. it won't _execute_ the Dockerfile to recreate the database). When this happens, it tries to start the database based on the new credentials which do not match the ones that the database was created with, and you get the error message mentioned in your first post.


If that is the case, and your object is to start a fresh production environment then you can delete the postgres volume.


결론적으로 환경변수 문제 였음


동일한 이름의 컨테이너를 다시 생성했을 때 볼륨이 살아있으면 발생한다고 함... (docker volume ls 로 볼륨 보고 rm 옵션주고 삭제할 것)



Ref.

https://github.com/pydanny/cookiecutter-django/issues/1678

https://github.com/docker-library/postgres/issues/203


+ Recent posts