cannot deploy docker, docker-api-1 throws authentication error, failed for user "postgres" #8037

Closed
opened 2026-02-21 18:23:35 -05:00 by yindo · 2 comments
Owner

Originally created by @Cyvadra on GitHub (Feb 7, 2025).

Self Checks

  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Provide a description of requested docs changes

cd dify
cd docker
cp .env.example .env

I have nginx running on port 80, so changed expose nginx port. Other settings remains the same.

docker compose up -d

Then I used reverse proxy to access website. /console/api/setup returned 500. So I run docker container logs docker-api-1

...
  File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/default.py", line 621, in connect
    return self.loaded_dbapi.connect(*cargs, **cparams)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/psycopg2/__init__.py", line 122, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/psycogreen/gevent.py", line 32, in gevent_wait_callback
    state = conn.poll()
            ^^^^^^^^^^^
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) FATAL:  password authentication failed for user "postgres"

(Background on this error at: https://sqlalche.me/e/20/e3q8)

And of course docker-db-1 showed failed access log.

I'm confused about where to modify settings? I've found .env.example under dify/api. Do I need to write another .env file? Otherwise how to deploy?

Originally created by @Cyvadra on GitHub (Feb 7, 2025). ### Self Checks - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [x] Please do not modify this template :) and fill in all the required fields. ### Provide a description of requested docs changes ```bash cd dify cd docker cp .env.example .env ``` I have nginx running on port 80, so changed expose nginx port. Other settings remains the same. ```bash docker compose up -d ``` Then I used reverse proxy to access website. `/console/api/setup` returned 500. So I run `docker container logs docker-api-1` ``` ... File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/default.py", line 621, in connect return self.loaded_dbapi.connect(*cargs, **cparams) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/psycopg2/__init__.py", line 122, in connect conn = _connect(dsn, connection_factory=connection_factory, **kwasync) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/psycogreen/gevent.py", line 32, in gevent_wait_callback state = conn.poll() ^^^^^^^^^^^ sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) FATAL: password authentication failed for user "postgres" (Background on this error at: https://sqlalche.me/e/20/e3q8) ``` And of course `docker-db-1` showed failed access log. I'm confused about where to modify settings? I've found .env.example under dify/api. Do I need to write another .env file? Otherwise how to deploy?
yindo closed this issue 2026-02-21 18:23:35 -05:00
Author
Owner

@crazywoola commented on GitHub (Feb 7, 2025):

Please check if you have installed the postgres on your machine already, if so, please stop the process and start it again.

I'm confused about where to modify settings? I've found .env.example under dify/api. Do I need to write another .env file? Otherwise how to deploy?

No you don't need to modify this.

@crazywoola commented on GitHub (Feb 7, 2025): Please check if you have installed the postgres on your machine already, if so, please stop the process and start it again. > I'm confused about where to modify settings? I've found .env.example under dify/api. Do I need to write another .env file? Otherwise how to deploy? No you don't need to modify this.
Author
Owner

@dosubot[bot] commented on GitHub (Feb 7, 2025):

Hello @Cyvadra! I'm here to help you with any bugs, questions, or contributions you have. Let's work together to solve the issue you're facing.

To resolve the authentication error for the user "postgres" when deploying Docker, ensure that the database connection credentials in your Docker Compose file match those expected by the PostgreSQL service. Here are the steps you should follow:

  1. Check the Credentials in docker-compose.yaml: Make sure the credentials for the PostgreSQL database are consistent. According to the docker-compose.yaml file, the credentials should be:

    DB_USERNAME: ${DB_USERNAME:-postgres}
    DB_PASSWORD: ${DB_PASSWORD:-difyai123456}
    DB_HOST: ${DB_HOST:-db}
    DB_PORT: ${DB_PORT:-5432}
    DB_DATABASE: dify
    

    These should match the environment variables set for the db service:

    db:
      image: postgres:15-alpine
      restart: always
      environment:
        PGUSER: ${PGUSER:-postgres}
        POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-difyai123456}
        POSTGRES_DB: ${POSTGRES_DB:-dify}
    
  2. Modify the .env File: You should create or modify a .env file under dify/api to ensure all environment variables are correctly set. You can start by copying the .env.example file to .env and then customize it as needed.

  3. Regenerate docker-compose.yaml: If you modify the .env.example or docker-compose-template.yaml, you need to regenerate the docker-compose.yaml file. Use the provided Python script to do this:

    python3 generate_docker_compose.py
    

This will ensure that the environment variables are correctly set and consistent across your services, resolving the authentication error [1][2].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@dosubot[bot] commented on GitHub (Feb 7, 2025): <!-- Greeting --> Hello @Cyvadra! I'm here to help you with any bugs, questions, or contributions you have. Let's work together to solve the issue you're facing. <!-- Answer --> To resolve the authentication error for the user "postgres" when deploying Docker, ensure that the database connection credentials in your Docker Compose file match those expected by the PostgreSQL service. Here are the steps you should follow: 1. **Check the Credentials in `docker-compose.yaml`:** Make sure the credentials for the PostgreSQL database are consistent. According to the `docker-compose.yaml` file, the credentials should be: ```yaml DB_USERNAME: ${DB_USERNAME:-postgres} DB_PASSWORD: ${DB_PASSWORD:-difyai123456} DB_HOST: ${DB_HOST:-db} DB_PORT: ${DB_PORT:-5432} DB_DATABASE: dify ``` These should match the environment variables set for the `db` service: ```yaml db: image: postgres:15-alpine restart: always environment: PGUSER: ${PGUSER:-postgres} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-difyai123456} POSTGRES_DB: ${POSTGRES_DB:-dify} ``` 2. **Modify the `.env` File:** You should create or modify a `.env` file under `dify/api` to ensure all environment variables are correctly set. You can start by copying the `.env.example` file to `.env` and then customize it as needed. 3. **Regenerate `docker-compose.yaml`:** If you modify the `.env.example` or `docker-compose-template.yaml`, you need to regenerate the `docker-compose.yaml` file. Use the provided Python script to do this: ```bash python3 generate_docker_compose.py ``` This will ensure that the environment variables are correctly set and consistent across your services, resolving the authentication error <sup>[[1]](https://github.com/langgenius/dify/blob/main/docker/docker-compose.yaml)</sup><sup>[[2]](https://github.com/langgenius/dify/blob/main/docker/generate_docker_compose)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* --- <sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/cd1d6989-2aee-46a7-b27a-1ca7ec6f6b33?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/cd1d6989-2aee-46a7-b27a-1ca7ec6f6b33?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/cd1d6989-2aee-46a7-b27a-1ca7ec6f6b33?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/cd1d6989-2aee-46a7-b27a-1ca7ec6f6b33?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/cd1d6989-2aee-46a7-b27a-1ca7ec6f6b33?feedback_type=hallucination) | [Other](https://app.dosu.dev/response-feedback/cd1d6989-2aee-46a7-b27a-1ca7ec6f6b33?feedback_type=other)</sup>
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#8037