我正在尝试在带有 odoo 的 docker 容器中使用 shell,但我遇到了一些问题。
我通过 docker-compose 设置本地环境,更准确地说,我在一个网络中运行 odoo 和 PostgreSQL,但是当我想为 odoo shell 指定 db 时,它不起作用。
这是我的 docker-compose.yaml:
version: '3'
services:
db:
image: postgres:10
ports:
- '5432:5432'
environment:
- POSTGRES_USER=odoo
- POSTGRES_PASSWORD=odoo
- POSTGRES_DB=postgres
volumes:
- odoo-db-data:/var/lib/postgresql/data
odoo:
depends_on:
- db
build: .
ports:
- '8069:8069'
- '8071:8071'
- '4444:4444'
volumes:
- odoo-web-data:/var/lib/odoo
- ./local_addons/:/mnt/extra-addons/
- ./odoo.conf:/etc/odoo/odoo.conf
stdin_open: true
tty: true
volumes:
odoo-web-data:
odoo-db-data:
和 Dockerfile(这很简单):
FROM odoo:13
USER root
RUN pip3 install remote-pdb pdbpp dateutils xlrd
USER odoo
odoo 实例本身工作得很好,因此 odoo 必须能够连接到数据库。但是当我尝试像这样执行shell时:
docker exec -it odoo_odoo_1 bash -c "odoo shell -d postgres"
我有这个例外(为了便于阅读,跟踪未满):
2019-10-29 14:37:13,094 72 INFO ? odoo: Odoo version 13.0-20191022
2019-10-29 14:37:13,095 72 INFO ? odoo: Using configuration file at /etc/odoo/odoo.conf
2019-10-29 14:37:13,095 72 INFO ? odoo: addons paths: ['/usr/lib/python3/dist-packages/odoo/addons', '/var/lib/odoo/addons/13.0', '/mnt/extra-addons']
2019-10-29 14:37:13,095 72 INFO ? odoo: database: default@default:default
2019-10-29 14:37:13,272 72 INFO ? odoo.addons.base.models.ir_actions_report: Will use the Wkhtmltopdf binary at /usr/local/bin/wkhtmltopdf
2019-10-29 14:37:13,377 72 INFO ? odoo.service.server: Initiating shutdown
2019-10-29 14:37:13,377 72 INFO ? odoo.service.server: Hit CTRL-C again or send a second signal to force the shutdown.
2019-10-29 14:37:13,378 72 INFO ? odoo.sql_db: Connection to the database failed
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/odoo/modules/registry.py", line 60, in __new__
return cls.registries[db_name]
File "/usr/lib/python3/dist-packages/odoo/tools/func.py", line 69, in wrapper
return func(self, *args, **kwargs)
File "/usr/lib/python3/dist-packages/odoo/tools/lru.py", line 44, in __getitem__
a = self.d[obj].me
KeyError: 'postgres'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/bin/odoo", line 8, in <module>
odoo.cli.main()
File "/usr/lib/python3/dist-packages/odoo/cli/command.py", line 60, in main
o.run(args)
.....
File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 600, in borrow
**connection_info)
File "/usr/lib/python3/dist-packages/psycopg2/__init__.py", line 126, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
我没有明确指定 postgres 主机和端口(这是我的 odoo.conf):
[options]
addons_path = /mnt/extra-addons
data_dir = /var/lib/odoo
debug_mode = True
; db_host = db
; db_port = 5432
; db_user = odoo
; db_password = odoo
; db_name = postgres
你有什么想法为什么我无法连接到数据库?