我正在尝试运行this project。当我在db和root中启动docker-compose时,出现以下错误:
backend_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 220, in ensure_connection
backend_1 | self.connect()
backend_1 | File "/usr/local/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__
backend_1 | raise dj_exc_value.with_traceback(traceback) from exc_value
backend_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 220, in ensure_connection
backend_1 | self.connect()
backend_1 | File "/usr/local/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
backend_1 | return func(*args, **kwargs)
backend_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 197, in connect
backend_1 | self.connection = self.get_new_connection(conn_params)
backend_1 | File "/usr/local/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
backend_1 | return func(*args, **kwargs)
backend_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/postgresql/base.py", line 185, in get_new_connection
backend_1 | connection = Database.connect(**conn_params)
backend_1 | File "/usr/local/lib/python3.8/site-packages/psycopg2/__init__.py", line 126, in connect
backend_1 | conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
backend_1 | django.db.utils.OperationalError: could not connect to server: Connection refused
backend_1 | Is the server running on host "192.168.1.107" and accepting
backend_1 | TCP/IP connections on port 5432?
从postgres docker我获得以下信息:
postgres_1 | 2020-03-21 09:49:56.090 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
postgres_1 | 2020-03-21 09:49:56.090 UTC [1] LOG: listening on IPv6 address "::", port 5432
所以,看来我的postgres运行在0.0.0.0上,后端正在尝试访问192.168.1.107。
我尝试将DB_HOST=192.168.1.107
中的DB_HOST=localhost
更改为.env.dev
,但不知怎么也不起作用。
我如何使其工作?