odoo 12 psycopg2.OperationalError: could not translate host name "db" to address

odoo 12 psycopg2.OperationalError: could not translate host name "db" to address

受影响的版本:

odoo 12,postgresql 10

重现步骤:

docker 个容器 odoo 容器几个月来工作得很好,但是在尝试升级 odoo 版本之后.. 我收到以下错误..

psycopg2.OperationalError: could not translate host name "db" to address

当前行为:

内部服务器错误 服务器遇到内部错误,无法完成您的请求。要么是服务器过载,要么是应用程序出错。

日志:

File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 171, in init , self._cnx = pool.borrow(dsn) , File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 540, in _locked , return fun(self, *args, **kwargs) , File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 608, in borrow , **connection_info) , File "/usr/lib/python3/dist-packages/psycopg2/init.py", line 130, in connect , conn = _connect(dsn, connection_factory=connection_factory, **kwasync) ,psycopg2.OperationalError: could not translate host name "db" to address: Name or service not known - - - ,2019-09-15 15:01:26,057 1 INFO ? odoo.service.server: Initiating shutdown ,2019-09-15 15:01:26,058 1 INFO ? odoo.service.server: Hit CTRL-C again or send a second signal to force the shutdown. ,2019-09-15 15:01:30,959 1 INFO ? odoo: Odoo version 12.0-20190816 ,2019-09-15 15:01:30,960 1 INFO ? odoo: Using configuration file at /etc/odoo/odoo.conf ,2019-09-15 15:01:30,960 1 INFO ? odoo: addons paths: ['/var/lib/odoo/addons/12.0', '/mnt/extra-addons', '/usr/lib/python3/dist-packages/odoo/addons'] ,2019-09-15 15:01:30,961 1 INFO ? odoo: database: odoo@db:5432 ,2019-09-15 15:01:31,104 1 INFO ? odoo.addons.base.models.ir_actions_report: Will use the Wkhtmltopdf binary at /usr/local/bin/wkhtmltopdf ,2019-09-15 15:01:31,265 1 INFO ? odoo.service.server: HTTP service (werkzeug) running on 574638c2fd44:8069 ,2019-09-15 15:01:40,043 1 INFO ? odoo.http: HTTP Configuring static files ,2019-09-15 15:01:40,072 1 INFO ? odoo.sql_db: Connection to the database failed ,2019-09-15 15:01:40,079 1 INFO ? werkzeug: - - [15/Sep/2019 15:01:40] "GET / HTTP/1.1" 500 - 0 0.000 0.031 ,2019-09-15 15:01:40,086 1 ERROR ? werkzeug: Error on request: , File "/usr/lib/python3/dist-packages/odoo/http.py", line 1320, in call , return self.dispatch(environ, start_response) , File "/usr/lib/python3/dist-packages/odoo/http.py", line 1293, in call , return self.app(environ, start_wrapped) , File "/usr/lib/python3/dist-packages/werkzeug/wsgi.py", line 599, in call , return self.app(environ, start_response) , File "/usr/lib/python3/dist-packages/odoo/http.py", line 1453, in dispatch , self.setup_db(httprequest) , File "/usr/lib/python3/dist-packages/odoo/http.py", line 1376, in setup_db , httprequest.session.db = db_monodb(httprequest) , File "/usr/lib/python3/dist-packages/odoo/http.py", line 1537, in db_monodb , dbs = db_list(True, httprequest) , File "/usr/lib/python3/dist-packages/odoo/http.py", line 1504, in db_list , dbs = odoo.service.db.list_dbs(force) , File "/usr/lib/python3/dist-packages/odoo/service/db.py", line 375, in list_dbs , with closing(db.cursor()) as cr: , File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 657, in cursor , return Cursor(self.pool, self.dbname, self.dsn, serialized=serialized) , File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 171, in __init , self._cnx = pool.borrow(dsn) , File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 540, in _locked , return fun(self, *args, **kwargs) , File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 608, in borrow , **connection_info) , File "/usr/lib/python3/dist-packages/psycopg2/init.py", line 130, in connect , conn = _connect(dsn, connection_factory=connection_factory, **kwasync) ,psycopg2.OperationalError: could not translate host name "db" to address: Name or service not known - - - ''''

您似乎缺少 docker 命令的 --link 选项。

你首先应该有 postgresql 容器 运行:

$ docker run -d -e POSTGRES_USER=odoo -e POSTGRES_PASSWORD=odoo -e POSTGRES_DB=postgres --name db postgres:10

如您所见,容器名称为db

然后你应该启动 odoo 实例并且 运行:

$ docker run -p 8069:8069 --name odoo --link db:db -t odoo

正如您在此处看到的,--link 选项告诉 odoo 容器将对 db 主机的所有请求映射到名为 db[=20= 的容器]

这是解决方案。

  • @ odoo.conf 我把 db_host = my_database_server_ip 改成了 db_host = db
  • 重启容器

恢复工作:)