An error occurs when port 5432 is occupied by another program, even though DB_PORT in the .env file has been changed to 5433. #8682

Closed
opened 2026-02-21 18:27:00 -05:00 by yindo · 6 comments
Owner

Originally created by @IncubatorShokuhou on GitHub (Feb 26, 2025).

Self Checks

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

Dify version

0.15.3

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

  1. install postgres by default, which will occupy port 5432
  2. change DB_PORT in .env to 5433
  3. install dify by docker compose

✔️ Expected Behavior

no error occour

Actual Behavior

Error response from daemon: driver failed programming external connectivity on endpoint docker-db-1 (1d166d9ffdded0d2b66475026ad5033576bfecd3b456ff925d6202bca1c9fdd9): Error starting userland proxy: listen tcp4 0.0.0.0:5432: bind: address already in use
Originally created by @IncubatorShokuhou on GitHub (Feb 26, 2025). ### Self Checks - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [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 this 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. ### Dify version 0.15.3 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce 1. install postgres by default, which will occupy port 5432 2. change `DB_PORT` in .env to 5433 3. install dify by docker compose ### ✔️ Expected Behavior no error occour ### ❌ Actual Behavior ```bash Error response from daemon: driver failed programming external connectivity on endpoint docker-db-1 (1d166d9ffdded0d2b66475026ad5033576bfecd3b456ff925d6202bca1c9fdd9): Error starting userland proxy: listen tcp4 0.0.0.0:5432: bind: address already in use ```
yindo added the 🐞 bug label 2026-02-21 18:27:00 -05:00
yindo closed this issue 2026-02-21 18:27:00 -05:00
Author
Owner

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

Hey @IncubatorShokuhou! I'm here to help you with any bugs, questions, or contributions you have for Dify. Let's work together to solve this issue!

The error occurs because the docker-compose.yaml file is still mapping the host port 5432 to the container's port 5432, despite changing the DB_PORT in the .env file to 5433. The line - '${EXPOSE_DB_PORT:-5432}:5432' in the docker-compose.yaml file is responsible for this mapping.

To resolve the issue, you need to ensure that the EXPOSE_DB_PORT environment variable is set to 5433 in your .env file or directly modify the docker-compose.yaml file to map the correct port:

ports:
  - '5433:5432'

This change will map the host port 5433 to the container's port 5432, resolving the port conflict [1].

To continue talking to Dosu, mention @dosu.


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

@dosubot[bot] commented on GitHub (Feb 26, 2025): <!-- Greeting --> Hey @IncubatorShokuhou! I'm here to help you with any bugs, questions, or contributions you have for Dify. Let's work together to solve this issue! <!-- Answer --> The error occurs because the `docker-compose.yaml` file is still mapping the host port 5432 to the container's port 5432, despite changing the `DB_PORT` in the `.env` file to 5433. The line `- '${EXPOSE_DB_PORT:-5432}:5432'` in the `docker-compose.yaml` file is responsible for this mapping. To resolve the issue, you need to ensure that the `EXPOSE_DB_PORT` environment variable is set to 5433 in your `.env` file or directly modify the `docker-compose.yaml` file to map the correct port: ```yaml ports: - '5433:5432' ``` This change will map the host port 5433 to the container's port 5432, resolving the port conflict <sup>[[1]](https://github.com/langgenius/dify/blob/main/docker/docker-compose.yaml)</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/35cdc93e-b68b-4a81-a497-d07c78ec2279?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/35cdc93e-b68b-4a81-a497-d07c78ec2279?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/35cdc93e-b68b-4a81-a497-d07c78ec2279?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/35cdc93e-b68b-4a81-a497-d07c78ec2279?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/35cdc93e-b68b-4a81-a497-d07c78ec2279?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/35cdc93e-b68b-4a81-a497-d07c78ec2279?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/35cdc93e-b68b-4a81-a497-d07c78ec2279?feedback_type=other)</sup>
Author
Owner

@IncubatorShokuhou commented on GitHub (Feb 26, 2025):

@dosubot So I need to change DB_PORT=5433 and add EXPOSE_DB_PORT=5433 in .env ?

@IncubatorShokuhou commented on GitHub (Feb 26, 2025): @dosubot So I need to change DB_PORT=5433 and add EXPOSE_DB_PORT=5433 in .env ?
Author
Owner

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

Yes, that's correct. You should set both DB_PORT=5433 and EXPOSE_DB_PORT=5433 in your .env file. This ensures that the environment variable EXPOSE_DB_PORT is used to map the correct port in the docker-compose.yaml file. After making these changes, restart your Docker containers to apply the new configuration.

To continue talking to Dosu, mention @dosu.


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

@dosubot[bot] commented on GitHub (Feb 26, 2025): <!-- Answer --> Yes, that's correct. You should set both `DB_PORT=5433` and `EXPOSE_DB_PORT=5433` in your `.env` file. This ensures that the environment variable `EXPOSE_DB_PORT` is used to map the correct port in the `docker-compose.yaml` file. After making these changes, restart your Docker containers to apply the new configuration. <!-- 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/b2a2caa4-102b-4e9b-9e34-7ceeeb55f354?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/b2a2caa4-102b-4e9b-9e34-7ceeeb55f354?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/b2a2caa4-102b-4e9b-9e34-7ceeeb55f354?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/b2a2caa4-102b-4e9b-9e34-7ceeeb55f354?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/b2a2caa4-102b-4e9b-9e34-7ceeeb55f354?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/b2a2caa4-102b-4e9b-9e34-7ceeeb55f354?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/b2a2caa4-102b-4e9b-9e34-7ceeeb55f354?feedback_type=other)</sup>
Author
Owner

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

@dosubot So I need to change DB_PORT=5433 and add EXPOSE_DB_PORT=5433 in .env ?

In your case, you only need to modify EXPOSE_DB_PORT . Or kill existing pg instance.

@crazywoola commented on GitHub (Feb 26, 2025): > @dosubot So I need to change DB_PORT=5433 and add EXPOSE_DB_PORT=5433 in .env ? In your case, you only need to modify `EXPOSE_DB_PORT `. Or kill existing pg instance.
Author
Owner

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

Hey @crazywoola! I'm here to help with bugs, technical questions, and engineering knowledge. It looks like you're diving into some configuration details. If you think I should have more to say on this, feel free to reach out to the Dosu Team.

To continue talking to Dosu, mention @dosu.


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

@dosubot[bot] commented on GitHub (Feb 26, 2025): <!-- Answer --> Hey @crazywoola! I'm here to help with bugs, technical questions, and engineering knowledge. It looks like you're diving into some configuration details. If you think I should have more to say on this, feel free to reach out to the [Dosu Team](mailto:customersuccess@dosu.dev). <!-- 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/2744f858-36c9-4c80-9b3a-dbb11454b6d7?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/2744f858-36c9-4c80-9b3a-dbb11454b6d7?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/2744f858-36c9-4c80-9b3a-dbb11454b6d7?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/2744f858-36c9-4c80-9b3a-dbb11454b6d7?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/2744f858-36c9-4c80-9b3a-dbb11454b6d7?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/2744f858-36c9-4c80-9b3a-dbb11454b6d7?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/2744f858-36c9-4c80-9b3a-dbb11454b6d7?feedback_type=other)</sup>
Author
Owner

@IncubatorShokuhou commented on GitHub (Feb 27, 2025):

@crazywoola

It works for me. Thank you!

@IncubatorShokuhou commented on GitHub (Feb 27, 2025): @crazywoola It works for me. Thank you!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#8682