When I launch dify and try to set up an admin account, the interface shows an "Internal Server Error" and keeps spinning. #6015

Closed
opened 2026-02-21 18:13:41 -05:00 by yindo · 7 comments
Owner

Originally created by @xiayi0409 on GitHub (Oct 10, 2024).

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

v0.9.1

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

微信截图_20241011001303
The front-end interface looks like this:

api-1 | 2024-10-10 16:10:50,042.042 ERROR [Dummy-1] [app.py:838] - Exception on /console/api/setup [GET]
api-1 | Traceback (most recent call last):
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 146, in init
api-1 | self._dbapi_connection = engine.raw_connection()
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 3302, in raw_connection
api-1 | return self.pool.connect()
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 449, in connect
api-1 | return _ConnectionFairy._checkout(self)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 1263, in _checkout
api-1 | fairy = _ConnectionRecord.checkout(pool)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 712, in checkout
api-1 | rec = pool._do_get()
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/impl.py", line 179, in _do_get
api-1 | with util.safe_reraise():
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 146, in exit
api-1 | raise exc_value.with_traceback(exc_tb)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/impl.py", line 177, in _do_get
api-1 | return self._create_connection()
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 390, in _create_connection
api-1 | return _ConnectionRecord(self)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 674, in init
api-1 | self.__connect()
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 900, in __connect
api-1 | with util.safe_reraise():
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 146, in exit
api-1 | raise exc_value.with_traceback(exc_tb)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 896, in __connect
api-1 | self.dbapi_connection = connection = pool._invoke_creator(self)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/create.py", line 643, in connect
api-1 | return dialect.connect(*cargs, **cparams)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 621, in connect
api-1 | return self.loaded_dbapi.connect(*cargs, **cparams)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/psycopg2/__init__.py", line 122, in connect
api-1 | conn = connect(dsn, connection_factory=connection_factory, **kwasync)
api-1 | psycopg2.OperationalError: could not translate host name "db" to address: Name or service not known
api-1 |
api-1 |
api-1 | The above exception was the direct cause of the following exception:
api-1 |
api-1 | Traceback (most recent call last):
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/flask/app.py", line 880, in full_dispatch_request
api-1 | rv = self.dispatch_request()
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/flask/app.py", line 865, in dispatch_request
api-1 | return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return]
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/flask_restful/__init__.py", line 489, in wrapper
api-1 | resp = resource(*args, **kwargs)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/flask/views.py", line 110, in view
api-1 | return current_app.ensure_sync(self.dispatch_request)(**kwargs) # type: ignore[no-any-return]
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/flask_restful/__init_
.py", line 604, in dispatch_request
api-1 | resp = meth(*args, **kwargs)
api-1 | File "/app/api/controllers/console/setup.py", line 21, in get
api-1 | setup_status = get_setup_status()
api-1 | File "/app/api/controllers/console/setup.py", line 72, in get_setup_status
api-1 | return DifySetup.query.first()
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/orm/query.py", line 2728, in first
api-1 | return self.limit(1)._iter().first() # type: ignore
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/orm/query.py", line 2827, in _iter
api-1 | result: Union[ScalarResult[_T], Result[_T]] = self.session.execute(
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 2362, in execute
api-1 | return self._execute_internal(
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 2237, in _execute_internal
api-1 | conn = self._connection_for_bind(bind)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 2106, in _connection_for_bind
api-1 | return trans._connection_for_bind(engine, execution_options)
api-1 | File "", line 2, in _connection_for_bind
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/orm/state_changes.py", line 139, in _go
api-1 | ret_value = fn(self, *arg, **kw)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 1189, in _connection_for_bind
api-1 | conn = bind.connect()
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 3278, in connect
api-1 | return self._connection_cls(self)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 148, in init
api-1 | Connection._handle_dbapi_exception_noconnection(
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 2442, in _handle_dbapi_exception_noconnection
api-1 | raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 146, in init
api-1 | self._dbapi_connection = engine.raw_connection()
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 3302, in raw_connection
api-1 | return self.pool.connect()
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 449, in connect
api-1 | return _ConnectionFairy._checkout(self)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 1263, in _checkout
api-1 | fairy = _ConnectionRecord.checkout(pool)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 712, in checkout
api-1 | rec = pool._do_get()
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/impl.py", line 179, in _do_get
api-1 | with util.safe_reraise():
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 146, in exit
api-1 | raise exc_value.with_traceback(exc_tb)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/impl.py", line 177, in _do_get
api-1 | return self._create_connection()
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 390, in _create_connection
api-1 | return _ConnectionRecord(self)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 674, in init
api-1 | self.__connect()
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 900, in __connect
api-1 | with util.safe_reraise():
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 146, in exit
api-1 | raise exc_value.with_traceback(exc_tb)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 896, in __connect
api-1 | self.dbapi_connection = connection = pool._invoke_creator(self)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/create.py", line 643, in connect
api-1 | return dialect.connect(*cargs, **cparams)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 621, in connect
api-1 | return self.loaded_dbapi.connect(*cargs, **cparams)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/psycopg2/__init__.py", line 122, in connect
api-1 | conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
api-1 | sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not translate host name "db" to address: Name or service not known
api-1 |
api-1 | (Background on this error at: https://sqlalche.me/e/20/e3q8)
nginx-1 | 10.198.84.27 - - [10/Oct/2024:16:10:50 +0000] "GET /console/api/setup HTTP/1.1" 500 56 "http://10.195.73.187/install" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36 Edg/124.0.0.0" "-"
nginx-1 | 10.198.84.27 - - [10/Oct/2024:16:10:58 +0000] "GET /install HTTP/1.1" 200 5453 "http://10.195.73.187/signin" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36 Edg/124.0.0.0" "-"
nginx-1 | 10.198.84.27 - - [10/Oct/2024:16:10:58 +0000] "GET /logo/logo-site.png HTTP/1.1" 304 0 "http://10.195.73.187/install" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36 Edg/124.0.0.0" "-"
nginx-1 | 10.198.84.27 - - [10/Oct/2024:16:10:58 +0000] "GET /favicon.ico HTTP/1.1" 304 0 "http://10.195.73.187/install" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36 Edg/124.0.0.0" "-"
api-1 | 2024-10-10 16:10:58,187.187 ERROR [Dummy-2] [app.py:838] - Exception on /console/api/setup [GET]
api-1 | Traceback (most recent call last):
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 146, in init
api-1 | self._dbapi_connection = engine.raw_connection()
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 3302, in raw_connection
api-1 | return self.pool.connect()
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 449, in connect
api-1 | return _ConnectionFairy._checkout(self)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 1263, in _checkout
api-1 | fairy = _ConnectionRecord.checkout(pool)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 712, in checkout
api-1 | rec = pool._do_get()
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/impl.py", line 179, in _do_get
api-1 | with util.safe_reraise():
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 146, in exit
api-1 | raise exc_value.with_traceback(exc_tb)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/impl.py", line 177, in _do_get
api-1 | return self._create_connection()
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 390, in _create_connection
api-1 | return _ConnectionRecord(self)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 674, in init
api-1 | self.__connect()
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 900, in __connect
api-1 | with util.safe_reraise():
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 146, in exit
api-1 | raise exc_value.with_traceback(exc_tb)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 896, in __connect
api-1 | self.dbapi_connection = connection = pool._invoke_creator(self)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/create.py", line 643, in connect
api-1 | return dialect.connect(*cargs, **cparams)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 621, in connect
api-1 | return self.loaded_dbapi.connect(*cargs, **cparams)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/psycopg2/__init__.py", line 122, in connect
api-1 | conn = connect(dsn, connection_factory=connection_factory, **kwasync)
api-1 | psycopg2.OperationalError: could not translate host name "db" to address: Name or service not known
api-1 |
api-1 |
api-1 | The above exception was the direct cause of the following exception:
api-1 |
api-1 | Traceback (most recent call last):
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/flask/app.py", line 880, in full_dispatch_request
api-1 | rv = self.dispatch_request()
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/flask/app.py", line 865, in dispatch_request
api-1 | return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return]
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/flask_restful/__init__.py", line 489, in wrapper
api-1 | resp = resource(*args, **kwargs)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/flask/views.py", line 110, in view
api-1 | return current_app.ensure_sync(self.dispatch_request)(**kwargs) # type: ignore[no-any-return]
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/flask_restful/__init_
.py", line 604, in dispatch_request
api-1 | resp = meth(*args, **kwargs)
api-1 | File "/app/api/controllers/console/setup.py", line 21, in get
api-1 | setup_status = get_setup_status()
api-1 | File "/app/api/controllers/console/setup.py", line 72, in get_setup_status
api-1 | return DifySetup.query.first()
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/orm/query.py", line 2728, in first
api-1 | return self.limit(1)._iter().first() # type: ignore
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/orm/query.py", line 2827, in _iter
api-1 | result: Union[ScalarResult[_T], Result[_T]] = self.session.execute(
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 2362, in execute
api-1 | return self._execute_internal(
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 2237, in _execute_internal
api-1 | conn = self._connection_for_bind(bind)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 2106, in _connection_for_bind
api-1 | return trans._connection_for_bind(engine, execution_options)
api-1 | File "", line 2, in _connection_for_bind
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/orm/state_changes.py", line 139, in _go
api-1 | ret_value = fn(self, *arg, **kw)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 1189, in _connection_for_bind
api-1 | conn = bind.connect()
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 3278, in connect
api-1 | return self._connection_cls(self)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 148, in init
api-1 | Connection._handle_dbapi_exception_noconnection(
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 2442, in _handle_dbapi_exception_noconnection
api-1 | raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 146, in init
api-1 | self._dbapi_connection = engine.raw_connection()
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 3302, in raw_connection
api-1 | return self.pool.connect()
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 449, in connect
api-1 | return _ConnectionFairy._checkout(self)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 1263, in _checkout
api-1 | fairy = _ConnectionRecord.checkout(pool)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 712, in checkout
api-1 | rec = pool._do_get()
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/impl.py", line 179, in _do_get
api-1 | with util.safe_reraise():
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 146, in exit
api-1 | raise exc_value.with_traceback(exc_tb)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/impl.py", line 177, in _do_get
api-1 | return self._create_connection()
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 390, in _create_connection
api-1 | return _ConnectionRecord(self)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 674, in init
api-1 | self.__connect()
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 900, in __connect
api-1 | with util.safe_reraise():
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 146, in exit
api-1 | raise exc_value.with_traceback(exc_tb)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 896, in __connect
api-1 | self.dbapi_connection = connection = pool._invoke_creator(self)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/create.py", line 643, in connect
api-1 | return dialect.connect(*cargs, **cparams)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 621, in connect
api-1 | return self.loaded_dbapi.connect(*cargs, **cparams)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/psycopg2/__init__.py", line 122, in connect
api-1 | conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
api-1 | sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not translate host name "db" to address: Name or service not known

As shown above, the "docker-compose up" command is displaying an error.

1

Changes based on similar issues cannot be implemented

✔️ Expected Behavior

Successfully registered user account

Actual Behavior

Error

Originally created by @xiayi0409 on GitHub (Oct 10, 2024). ### 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 v0.9.1 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce ![微信截图_20241011001303](https://github.com/user-attachments/assets/02c0120e-212b-4797-a8a2-53dc37d5dbbd) The front-end interface looks like this: api-1 | 2024-10-10 16:10:50,042.042 ERROR [Dummy-1] [app.py:838] - Exception on /console/api/setup [GET] api-1 | Traceback (most recent call last): api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 146, in __init__ api-1 | self._dbapi_connection = engine.raw_connection() api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 3302, in raw_connection api-1 | return self.pool.connect() api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 449, in connect api-1 | return _ConnectionFairy._checkout(self) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 1263, in _checkout api-1 | fairy = _ConnectionRecord.checkout(pool) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 712, in checkout api-1 | rec = pool._do_get() api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/impl.py", line 179, in _do_get api-1 | with util.safe_reraise(): api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 146, in __exit__ api-1 | raise exc_value.with_traceback(exc_tb) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/impl.py", line 177, in _do_get api-1 | return self._create_connection() api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 390, in _create_connection api-1 | return _ConnectionRecord(self) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 674, in __init__ api-1 | self.__connect() api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 900, in __connect api-1 | with util.safe_reraise(): api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 146, in __exit__ api-1 | raise exc_value.with_traceback(exc_tb) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 896, in __connect api-1 | self.dbapi_connection = connection = pool._invoke_creator(self) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/create.py", line 643, in connect api-1 | return dialect.connect(*cargs, **cparams) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 621, in connect api-1 | return self.loaded_dbapi.connect(*cargs, **cparams) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/psycopg2/__init__.py", line 122, in connect api-1 | conn = _connect(dsn, connection_factory=connection_factory, **kwasync) api-1 | psycopg2.OperationalError: could not translate host name "db" to address: Name or service not known api-1 | api-1 | api-1 | The above exception was the direct cause of the following exception: api-1 | api-1 | Traceback (most recent call last): api-1 | File "/app/api/.venv/lib/python3.10/site-packages/flask/app.py", line 880, in full_dispatch_request api-1 | rv = self.dispatch_request() api-1 | File "/app/api/.venv/lib/python3.10/site-packages/flask/app.py", line 865, in dispatch_request api-1 | return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return] api-1 | File "/app/api/.venv/lib/python3.10/site-packages/flask_restful/__init__.py", line 489, in wrapper api-1 | resp = resource(*args, **kwargs) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/flask/views.py", line 110, in view api-1 | return current_app.ensure_sync(self.dispatch_request)(**kwargs) # type: ignore[no-any-return] api-1 | File "/app/api/.venv/lib/python3.10/site-packages/flask_restful/__init__.py", line 604, in dispatch_request api-1 | resp = meth(*args, **kwargs) api-1 | File "/app/api/controllers/console/setup.py", line 21, in get api-1 | setup_status = get_setup_status() api-1 | File "/app/api/controllers/console/setup.py", line 72, in get_setup_status api-1 | return DifySetup.query.first() api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/orm/query.py", line 2728, in first api-1 | return self.limit(1)._iter().first() # type: ignore api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/orm/query.py", line 2827, in _iter api-1 | result: Union[ScalarResult[_T], Result[_T]] = self.session.execute( api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 2362, in execute api-1 | return self._execute_internal( api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 2237, in _execute_internal api-1 | conn = self._connection_for_bind(bind) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 2106, in _connection_for_bind api-1 | return trans._connection_for_bind(engine, execution_options) api-1 | File "<string>", line 2, in _connection_for_bind api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/orm/state_changes.py", line 139, in _go api-1 | ret_value = fn(self, *arg, **kw) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 1189, in _connection_for_bind api-1 | conn = bind.connect() api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 3278, in connect api-1 | return self._connection_cls(self) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 148, in __init__ api-1 | Connection._handle_dbapi_exception_noconnection( api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 2442, in _handle_dbapi_exception_noconnection api-1 | raise sqlalchemy_exception.with_traceback(exc_info[2]) from e api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 146, in __init__ api-1 | self._dbapi_connection = engine.raw_connection() api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 3302, in raw_connection api-1 | return self.pool.connect() api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 449, in connect api-1 | return _ConnectionFairy._checkout(self) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 1263, in _checkout api-1 | fairy = _ConnectionRecord.checkout(pool) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 712, in checkout api-1 | rec = pool._do_get() api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/impl.py", line 179, in _do_get api-1 | with util.safe_reraise(): api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 146, in __exit__ api-1 | raise exc_value.with_traceback(exc_tb) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/impl.py", line 177, in _do_get api-1 | return self._create_connection() api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 390, in _create_connection api-1 | return _ConnectionRecord(self) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 674, in __init__ api-1 | self.__connect() api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 900, in __connect api-1 | with util.safe_reraise(): api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 146, in __exit__ api-1 | raise exc_value.with_traceback(exc_tb) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 896, in __connect api-1 | self.dbapi_connection = connection = pool._invoke_creator(self) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/create.py", line 643, in connect api-1 | return dialect.connect(*cargs, **cparams) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 621, in connect api-1 | return self.loaded_dbapi.connect(*cargs, **cparams) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/psycopg2/__init__.py", line 122, in connect api-1 | conn = _connect(dsn, connection_factory=connection_factory, **kwasync) api-1 | sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not translate host name "db" to address: Name or service not known api-1 | api-1 | (Background on this error at: https://sqlalche.me/e/20/e3q8) nginx-1 | 10.198.84.27 - - [10/Oct/2024:16:10:50 +0000] "GET /console/api/setup HTTP/1.1" 500 56 "http://10.195.73.187/install" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36 Edg/124.0.0.0" "-" nginx-1 | 10.198.84.27 - - [10/Oct/2024:16:10:58 +0000] "GET /install HTTP/1.1" 200 5453 "http://10.195.73.187/signin" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36 Edg/124.0.0.0" "-" nginx-1 | 10.198.84.27 - - [10/Oct/2024:16:10:58 +0000] "GET /logo/logo-site.png HTTP/1.1" 304 0 "http://10.195.73.187/install" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36 Edg/124.0.0.0" "-" nginx-1 | 10.198.84.27 - - [10/Oct/2024:16:10:58 +0000] "GET /favicon.ico HTTP/1.1" 304 0 "http://10.195.73.187/install" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36 Edg/124.0.0.0" "-" api-1 | 2024-10-10 16:10:58,187.187 ERROR [Dummy-2] [app.py:838] - Exception on /console/api/setup [GET] api-1 | Traceback (most recent call last): api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 146, in __init__ api-1 | self._dbapi_connection = engine.raw_connection() api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 3302, in raw_connection api-1 | return self.pool.connect() api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 449, in connect api-1 | return _ConnectionFairy._checkout(self) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 1263, in _checkout api-1 | fairy = _ConnectionRecord.checkout(pool) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 712, in checkout api-1 | rec = pool._do_get() api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/impl.py", line 179, in _do_get api-1 | with util.safe_reraise(): api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 146, in __exit__ api-1 | raise exc_value.with_traceback(exc_tb) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/impl.py", line 177, in _do_get api-1 | return self._create_connection() api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 390, in _create_connection api-1 | return _ConnectionRecord(self) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 674, in __init__ api-1 | self.__connect() api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 900, in __connect api-1 | with util.safe_reraise(): api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 146, in __exit__ api-1 | raise exc_value.with_traceback(exc_tb) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 896, in __connect api-1 | self.dbapi_connection = connection = pool._invoke_creator(self) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/create.py", line 643, in connect api-1 | return dialect.connect(*cargs, **cparams) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 621, in connect api-1 | return self.loaded_dbapi.connect(*cargs, **cparams) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/psycopg2/__init__.py", line 122, in connect api-1 | conn = _connect(dsn, connection_factory=connection_factory, **kwasync) api-1 | psycopg2.OperationalError: could not translate host name "db" to address: Name or service not known api-1 | api-1 | api-1 | The above exception was the direct cause of the following exception: api-1 | api-1 | Traceback (most recent call last): api-1 | File "/app/api/.venv/lib/python3.10/site-packages/flask/app.py", line 880, in full_dispatch_request api-1 | rv = self.dispatch_request() api-1 | File "/app/api/.venv/lib/python3.10/site-packages/flask/app.py", line 865, in dispatch_request api-1 | return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return] api-1 | File "/app/api/.venv/lib/python3.10/site-packages/flask_restful/__init__.py", line 489, in wrapper api-1 | resp = resource(*args, **kwargs) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/flask/views.py", line 110, in view api-1 | return current_app.ensure_sync(self.dispatch_request)(**kwargs) # type: ignore[no-any-return] api-1 | File "/app/api/.venv/lib/python3.10/site-packages/flask_restful/__init__.py", line 604, in dispatch_request api-1 | resp = meth(*args, **kwargs) api-1 | File "/app/api/controllers/console/setup.py", line 21, in get api-1 | setup_status = get_setup_status() api-1 | File "/app/api/controllers/console/setup.py", line 72, in get_setup_status api-1 | return DifySetup.query.first() api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/orm/query.py", line 2728, in first api-1 | return self.limit(1)._iter().first() # type: ignore api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/orm/query.py", line 2827, in _iter api-1 | result: Union[ScalarResult[_T], Result[_T]] = self.session.execute( api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 2362, in execute api-1 | return self._execute_internal( api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 2237, in _execute_internal api-1 | conn = self._connection_for_bind(bind) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 2106, in _connection_for_bind api-1 | return trans._connection_for_bind(engine, execution_options) api-1 | File "<string>", line 2, in _connection_for_bind api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/orm/state_changes.py", line 139, in _go api-1 | ret_value = fn(self, *arg, **kw) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 1189, in _connection_for_bind api-1 | conn = bind.connect() api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 3278, in connect api-1 | return self._connection_cls(self) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 148, in __init__ api-1 | Connection._handle_dbapi_exception_noconnection( api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 2442, in _handle_dbapi_exception_noconnection api-1 | raise sqlalchemy_exception.with_traceback(exc_info[2]) from e api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 146, in __init__ api-1 | self._dbapi_connection = engine.raw_connection() api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 3302, in raw_connection api-1 | return self.pool.connect() api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 449, in connect api-1 | return _ConnectionFairy._checkout(self) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 1263, in _checkout api-1 | fairy = _ConnectionRecord.checkout(pool) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 712, in checkout api-1 | rec = pool._do_get() api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/impl.py", line 179, in _do_get api-1 | with util.safe_reraise(): api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 146, in __exit__ api-1 | raise exc_value.with_traceback(exc_tb) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/impl.py", line 177, in _do_get api-1 | return self._create_connection() api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 390, in _create_connection api-1 | return _ConnectionRecord(self) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 674, in __init__ api-1 | self.__connect() api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 900, in __connect api-1 | with util.safe_reraise(): api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 146, in __exit__ api-1 | raise exc_value.with_traceback(exc_tb) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 896, in __connect api-1 | self.dbapi_connection = connection = pool._invoke_creator(self) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/create.py", line 643, in connect api-1 | return dialect.connect(*cargs, **cparams) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 621, in connect api-1 | return self.loaded_dbapi.connect(*cargs, **cparams) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/psycopg2/__init__.py", line 122, in connect api-1 | conn = _connect(dsn, connection_factory=connection_factory, **kwasync) api-1 | sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not translate host name "db" to address: Name or service not known As shown above, the "docker-compose up" command is displaying an error. <img width="864" alt="1" src="https://github.com/user-attachments/assets/241468ba-4a80-4172-8f6e-c99c4509fc0b"> Changes based on similar issues cannot be implemented ### ✔️ Expected Behavior Successfully registered user account ### ❌ Actual Behavior Error
yindo added the 🤔 cant-reproduce label 2026-02-21 18:13:41 -05:00
yindo closed this issue 2026-02-21 18:13:41 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Oct 10, 2024):

Hey @xiayi0409! 👋 I'm here to help you with any bugs, questions, or even becoming a contributor. Let's squash those bugs together!

The "Internal Server Error" you're encountering is likely due to a misconfiguration in your Docker setup, specifically with the database connection. The error message indicates that the hostname "db" cannot be resolved.

Here are some steps to resolve this issue:

  1. Check Docker Compose Configuration: Ensure that the database service is correctly defined in your docker-compose.yaml file. The service name should match the hostname used in your application configuration.

  2. Verify Environment Variables: Make sure your .env file has the correct database connection settings. The DB_HOST should match the service name defined in your Docker Compose file.

  3. Network Configuration: Ensure that all services are on the same Docker network. You can specify a network in your Docker Compose file to ensure proper communication between services.

  4. Restart Docker Containers: After making changes, restart your Docker containers using docker-compose down and docker-compose up -d.

These steps should help resolve the issue with the database connection [1].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Oct 10, 2024): <!-- Greeting --> Hey @xiayi0409! 👋 I'm here to help you with any bugs, questions, or even becoming a contributor. Let's squash those bugs together! <!-- Answer --> The "Internal Server Error" you're encountering is likely due to a misconfiguration in your Docker setup, specifically with the database connection. The error message indicates that the hostname "db" cannot be resolved. Here are some steps to resolve this issue: 1. **Check Docker Compose Configuration**: Ensure that the database service is correctly defined in your `docker-compose.yaml` file. The service name should match the hostname used in your application configuration. 2. **Verify Environment Variables**: Make sure your `.env` file has the correct database connection settings. The `DB_HOST` should match the service name defined in your Docker Compose file. 3. **Network Configuration**: Ensure that all services are on the same Docker network. You can specify a network in your Docker Compose file to ensure proper communication between services. 4. **Restart Docker Containers**: After making changes, restart your Docker containers using `docker-compose down` and `docker-compose up -d`. These steps should help resolve the issue with the database connection <sup>[[1]](https://github.com/langgenius/dify/issues/6479)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@xiayi0409 commented on GitHub (Oct 10, 2024):

I have checked what you said, but the problem still appears. This is an error from docker compose up

api-1 | Preparing database migration...
api-1 | Starting database migration.
api-1 | ERROR [root] Database migration failed: (psycopg2.OperationalError) connection to server at "db" (172.20.0.4), port 5432 failed: Connection refused
api-1 | Is the server running on that host and accepting TCP/IP connections?
api-1 |
api-1 | (Background on this error at: https://sqlalche.me/e/20/e3q8)
api-1 | Traceback (most recent call last):
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 146, in init
api-1 | self._dbapi_connection = engine.raw_connection()
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 3302, in raw_connection
api-1 | return self.pool.connect()
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 449, in connect
api-1 | return _ConnectionFairy._checkout(self)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 1263, in _checkout
api-1 | fairy = _ConnectionRecord.checkout(pool)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 712, in checkout
api-1 | rec = pool._do_get()
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/impl.py", line 179, in _do_get
api-1 | with util.safe_reraise():
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 146, in exit
api-1 | raise exc_value.with_traceback(exc_tb)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/impl.py", line 177, in _do_get
api-1 | return self._create_connection()
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 390, in _create_connection
api-1 | return _ConnectionRecord(self)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 674, in init
api-1 | self.__connect()
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 900, in __connect
api-1 | with util.safe_reraise():
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 146, in exit
api-1 | raise exc_value.with_traceback(exc_tb)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 896, in __connect
api-1 | self.dbapi_connection = connection = pool._invoke_creator(self)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/create.py", line 643, in connect
api-1 | return dialect.connect(*cargs, **cparams)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 621, in connect
api-1 | return self.loaded_dbapi.connect(*cargs, **cparams)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/psycopg2/init.py", line 122, in connect
api-1 | conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
api-1 | psycopg2.OperationalError: connection to server at "db" (172.20.0.4), port 5432 failed: Connection refused
api-1 | Is the server running on that host and accepting TCP/IP connections?
api-1 |
api-1 |
api-1 | The above exception was the direct cause of the following exception:
api-1 |
api-1 | Traceback (most recent call last):
api-1 | File "/app/api/commands.py", line 607, in upgrade_db
api-1 | flask_migrate.upgrade()
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/flask_migrate/init.py", line 111, in wrapped
api-1 | f(*args, **kwargs)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/flask_migrate/init.py", line 200, in upgrade
api-1 | command.upgrade(config, revision, sql=sql, tag=tag)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/alembic/command.py", line 406, in upgrade
api-1 | script.run_env()
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/alembic/script/base.py", line 586, in run_env
api-1 | util.load_python_file(self.dir, "env.py")
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/alembic/util/pyfiles.py", line 95, in load_python_file
api-1 | module = load_module_py(module_id, path)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/alembic/util/pyfiles.py", line 113, in load_module_py
api-1 | spec.loader.exec_module(module) # type: ignore
api-1 | File "", line 883, in exec_module
api-1 | File "", line 241, in _call_with_frames_removed
api-1 | File "/app/api/migrations/env.py", line 112, in
api-1 | run_migrations_online()
api-1 | File "/app/api/migrations/env.py", line 96, in run_migrations_online
api-1 | with connectable.connect() as connection:
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 3278, in connect
api-1 | return self._connection_cls(self)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 148, in init
api-1 | Connection._handle_dbapi_exception_noconnection(
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 2442, in _handle_dbapi_exception_noconnection
api-1 | raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 146, in init
api-1 | self._dbapi_connection = engine.raw_connection()
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 3302, in raw_connection
api-1 | return self.pool.connect()
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 449, in connect
api-1 | return _ConnectionFairy._checkout(self)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 1263, in _checkout
api-1 | fairy = _ConnectionRecord.checkout(pool)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 712, in checkout
api-1 | rec = pool._do_get()
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/impl.py", line 179, in _do_get
api-1 | with util.safe_reraise():
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 146, in exit
api-1 | raise exc_value.with_traceback(exc_tb)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/impl.py", line 177, in _do_get
api-1 | return self._create_connection()
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 390, in _create_connection
api-1 | return _ConnectionRecord(self)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 674, in init
api-1 | self.__connect()
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 900, in __connect
api-1 | with util.safe_reraise():
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 146, in exit
api-1 | raise exc_value.with_traceback(exc_tb)
api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/p
@dosu

@xiayi0409 commented on GitHub (Oct 10, 2024): I have checked what you said, but the problem still appears. This is an error from docker compose up api-1 | Preparing database migration... api-1 | Starting database migration. api-1 | ERROR [root] Database migration failed: (psycopg2.OperationalError) connection to server at "db" (172.20.0.4), port 5432 failed: Connection refused api-1 | Is the server running on that host and accepting TCP/IP connections? api-1 | api-1 | (Background on this error at: https://sqlalche.me/e/20/e3q8) api-1 | Traceback (most recent call last): api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 146, in init api-1 | self._dbapi_connection = engine.raw_connection() api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 3302, in raw_connection api-1 | return self.pool.connect() api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 449, in connect api-1 | return _ConnectionFairy._checkout(self) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 1263, in _checkout api-1 | fairy = _ConnectionRecord.checkout(pool) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 712, in checkout api-1 | rec = pool._do_get() api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/impl.py", line 179, in _do_get api-1 | with util.safe_reraise(): api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 146, in exit api-1 | raise exc_value.with_traceback(exc_tb) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/impl.py", line 177, in _do_get api-1 | return self._create_connection() api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 390, in _create_connection api-1 | return _ConnectionRecord(self) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 674, in init api-1 | self.__connect() api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 900, in __connect api-1 | with util.safe_reraise(): api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 146, in exit api-1 | raise exc_value.with_traceback(exc_tb) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 896, in __connect api-1 | self.dbapi_connection = connection = pool._invoke_creator(self) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/create.py", line 643, in connect api-1 | return dialect.connect(*cargs, **cparams) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 621, in connect api-1 | return self.loaded_dbapi.connect(*cargs, **cparams) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/psycopg2/init.py", line 122, in connect api-1 | conn = _connect(dsn, connection_factory=connection_factory, **kwasync) api-1 | psycopg2.OperationalError: connection to server at "db" (172.20.0.4), port 5432 failed: Connection refused api-1 | Is the server running on that host and accepting TCP/IP connections? api-1 | api-1 | api-1 | The above exception was the direct cause of the following exception: api-1 | api-1 | Traceback (most recent call last): api-1 | File "/app/api/commands.py", line 607, in upgrade_db api-1 | flask_migrate.upgrade() api-1 | File "/app/api/.venv/lib/python3.10/site-packages/flask_migrate/init.py", line 111, in wrapped api-1 | f(*args, **kwargs) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/flask_migrate/init.py", line 200, in upgrade api-1 | command.upgrade(config, revision, sql=sql, tag=tag) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/alembic/command.py", line 406, in upgrade api-1 | script.run_env() api-1 | File "/app/api/.venv/lib/python3.10/site-packages/alembic/script/base.py", line 586, in run_env api-1 | util.load_python_file(self.dir, "env.py") api-1 | File "/app/api/.venv/lib/python3.10/site-packages/alembic/util/pyfiles.py", line 95, in load_python_file api-1 | module = load_module_py(module_id, path) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/alembic/util/pyfiles.py", line 113, in load_module_py api-1 | spec.loader.exec_module(module) # type: ignore api-1 | File "", line 883, in exec_module api-1 | File "", line 241, in _call_with_frames_removed api-1 | File "/app/api/migrations/env.py", line 112, in api-1 | run_migrations_online() api-1 | File "/app/api/migrations/env.py", line 96, in run_migrations_online api-1 | with connectable.connect() as connection: api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 3278, in connect api-1 | return self._connection_cls(self) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 148, in init api-1 | Connection._handle_dbapi_exception_noconnection( api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 2442, in _handle_dbapi_exception_noconnection api-1 | raise sqlalchemy_exception.with_traceback(exc_info[2]) from e api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 146, in init api-1 | self._dbapi_connection = engine.raw_connection() api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 3302, in raw_connection api-1 | return self.pool.connect() api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 449, in connect api-1 | return _ConnectionFairy._checkout(self) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 1263, in _checkout api-1 | fairy = _ConnectionRecord.checkout(pool) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 712, in checkout api-1 | rec = pool._do_get() api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/impl.py", line 179, in _do_get api-1 | with util.safe_reraise(): api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 146, in exit api-1 | raise exc_value.with_traceback(exc_tb) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/impl.py", line 177, in _do_get api-1 | return self._create_connection() api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 390, in _create_connection api-1 | return _ConnectionRecord(self) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 674, in init api-1 | self.__connect() api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 900, in __connect api-1 | with util.safe_reraise(): api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 146, in exit api-1 | raise exc_value.with_traceback(exc_tb) api-1 | File "/app/api/.venv/lib/python3.10/site-packages/sqlalchemy/p @dosu
Author
Owner

@dosubot[bot] commented on GitHub (Oct 10, 2024):

The error "connection to server at 'db' (172.20.0.4), port 5432 failed: Connection refused" suggests that the database service might not be ready when the migration script attempts to connect.

To address this, ensure that your docker-compose.yaml includes a health check for the database service and that the service running the migration script waits for the database to be ready. Here's how you can configure it:

  1. Health Check for Database: Ensure your db service has a health check like this:

    healthcheck:
      test: ["CMD", "pg_isready"]
      interval: 1s
      timeout: 3s
      retries: 30
    
  2. Service Dependency: Use depends_on with condition: service_healthy for the service that runs the migration:

    depends_on:
      db:
        condition: service_healthy
    

This setup ensures that the migration script waits until the database is fully ready to accept connections [1].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Oct 10, 2024): <!-- Answer --> The error "connection to server at 'db' (172.20.0.4), port 5432 failed: Connection refused" suggests that the database service might not be ready when the migration script attempts to connect. To address this, ensure that your `docker-compose.yaml` includes a health check for the database service and that the service running the migration script waits for the database to be ready. Here's how you can configure it: 1. **Health Check for Database**: Ensure your `db` service has a health check like this: ```yaml healthcheck: test: ["CMD", "pg_isready"] interval: 1s timeout: 3s retries: 30 ``` 2. **Service Dependency**: Use `depends_on` with `condition: service_healthy` for the service that runs the migration: ```yaml depends_on: db: condition: service_healthy ``` This setup ensures that the migration script waits until the database is fully ready to accept connections <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.*
Author
Owner

@crazywoola commented on GitHub (Oct 10, 2024):

You just need to fix the connection between api and db. Either you have something wrong with the db or your network because containers has something wrong

@crazywoola commented on GitHub (Oct 10, 2024): You just need to fix the connection between api and db. Either you have something wrong with the db or your network because containers has something wrong
Author
Owner

@oscar66oliver commented on GitHub (Oct 10, 2024):

I have the same error. This is the first time that I use docker in WSL2 to install Dify. This error didn't occur on mac or linux.

@oscar66oliver commented on GitHub (Oct 10, 2024): I have the same error. This is the first time that I use docker in WSL2 to install Dify. This error didn't occur on mac or linux.
Author
Owner

@nadazero commented on GitHub (Oct 11, 2024):

I have met same error and I have solved it. Root cause is linux permission issues , you should modify docker-compose.yaml

@nadazero commented on GitHub (Oct 11, 2024): I have met same error and I have solved it. Root cause is linux permission issues , you should modify docker-compose.yaml
Author
Owner

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

@xiayi0409 I encounter the same issue. How did you fix it then? I am using WSL2.

@zhiyzheng commented on GitHub (Feb 27, 2025): @xiayi0409 I encounter the same issue. How did you fix it then? I am using WSL2.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#6015