如何在Docker中调试odoo? [英] How to debug odoo in docker?

查看:195
本文介绍了如何在Docker中调试odoo?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在Docker容器中调试odoo。



我正在使用Visual Studio Code,并且具有以下launch.json配置。

  {
version: 0.2.0,
configuration:[
{
name: Odoo 12,
type: python,
request:启动,
stopOnEntry:false,
pythonPath: $ {config:python.pythonPath},
program: / usr / bin / odoo,
args:[
--config = / etc / odoo / odoo.conf
]
}
]
}

每次我启动调试器时,错误发生:

 线程odoo.service中的异常。httpd:
追溯(最近一次调用):
文件 /usr/lib/python3.5/threading.py,行914,在_bootstrap_inner中
self.run()
文件 /usr/lib/python3.5/threading.py ,第862行,在运行
中self._target(* self._args,** self._kwargs)
File / usr / lib / pyt hon3 / dist-packages / odoo / service / server.py,行410,在http_thread
self.httpd = ThreadedWSGIServerReloadable(self.interface,self.port,app)
文件 / usr / lib /python3/dist-packages/odoo/service/server.py,第136行,位于__init__
handler = RequestHandler)
文件 / usr / lib / python3 / dist-packages / werkzeug / serving。 py,第476行,位于__init__
HTTPServer .__ init __(自身,(主机,int(端口)),处理程序)
文件 /usr/lib/python3.5/socketserver.py,第440,在__init__
self.server_bind()
文件 /usr/lib/python3/dist-packages/odoo/service/server.py中,第151行,在server_bind
super( ThreadedWSGIServerReloadable,self).server_bind()
在server_bind
socketserver.TCPServer.server_bind(self)$ b $中的文件 /usr/lib/python3.5/http/server.py,第138行b server_bind
self.socket.bind(self.server_address)
中的文件 /usr/lib/python3.5/socketserver.py,行454
OSError:[Errno 98]地址已在使用中

有人知道我的调试配置出了什么问题吗?



谢谢!



更新



也许需要更多信息。
我使用docker-compose文件启动odoo服务器,然后使用VSCode远程连接到该odoo服务器。
使用odoo-bin命令重新启动服务器,可以在VSCode终端上正常运行。



我有两个正在运行的Docker容器:

 容器ID图像命令创建的状态端口名称
4ac4a4c8481f odoo:12.0 /entrypoint.sh odoo… 7天前向上4分钟0.0.0.0:8069->8069/tcp,8071 / tcp odoo-docker_web_1
5910cce38985 postgres :10 docker-entrypoint.s… 7天前向上4分钟5432 / tcp odoo-docker_db_1

并且只有odoo服务器正在8069上运行:

  odoo @ 4ac4a4c8481f:/ mnt / extra-addons $ lsof -i:8069 
命令PID用户FD类型设备大小/关闭节点名称
python3 1 odoo 7u IPv4 44986 0t0 TCP *:8069(LISTEN)

所以我可能使用启动请求类型是错误的,因为它试图重新启动服务器。
我还测试了此配置:

  {
name: Odoo 12 Attach,
type: python,
request: attach,
port:8069,
host: localhost,
},

,但随后调试器将立即终止,而不会出现错误消息。

解决方案

为了了解远程调试如何针对基于python的所有python服务或应用(例如Odoo,Flask,Django,Web2py等。您必须了解Docker容器,调试器,python应用服务器(在我们的示例中为Odoo)这三个不同的概念。因此,在很多情况下,从docker运行Odoo时,如下图所示:


请注意区别:



  • 无需调试,您就有两个端口,一个是内部端口,另一个是外部端口,它将HTTP请求从浏览器传递到Odoo&反之亦然。但是,在调试之后,您有4个端口,其中2个用于http请求&其他2个用于调试信息(在我们的案例中基于json)从Vscode到 debugpy &反之亦然(您也可以使用2个端口)。

  • 不调试您的入口点就是 Dockerfile 中定义的内容。通过调试,您可以将入口点修改为 debugpy 。这将负责运行Odoo


czuniga,这种方法真的很好&几乎与以下内容相同:


vscode 1.45.0 &后来。供参考文件 https://gist.github.com/kerbrose/e646aaf9daece42b46091e2ca0eb55d0


1-编辑您的 docker.dev 文件&插入运行pip3 install -U debugpy 。这将安装python软件包 debugpy 而不是已弃用的 ptvsd ,因为您的vscode(本地)将与 debugpy (远程)服务器镜像的服务器。


2-启动容器。但是,您将启动刚刚安装了 debugpy 的python软件包。

  docker-compose run --rm -p 8888:3001- p 8879:8069 {DOCKER IMAGE [:TAG | @DIGEST]} / usr / bin / python3 -m debugpy --listen 0.0.0.0:3001 / usr / bin / odoo --db_user = odoo --db_host = db- db_password = odoo 

3-准备启动程序文件如下。请注意,端口将与odoo服务器相关。 debugServer 将成为调试服务器的端口

  { 
名称: Odoo:附加,
类型: python,
请求:附加,
端口:8879,
debugServer:8888,
主机: localhost,
pathMappings:[
{
; localRoot: $ {workspaceFolder},
remoteRoot: / mnt / extra-addons,
}
],
logToFile ;:真正的


I am not able to debug odoo in docker container.

I am using Visual Studio Code and I have the following launch.json configuration.

{
   "version": "0.2.0",
   "configurations": [
       {
           "name": "Odoo 12",
           "type": "python",
           "request": "launch",
           "stopOnEntry": false,
           "pythonPath": "${config:python.pythonPath}",
           "program": "/usr/bin/odoo",
           "args": [
             "--config=/etc/odoo/odoo.conf"
           ]
       }
   ]
}

Everytime I start a debugger, this error occurs:

Exception in thread odoo.service.httpd:
Traceback (most recent call last):
  File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.5/threading.py", line 862, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/lib/python3/dist-packages/odoo/service/server.py", line 410, in http_thread
    self.httpd = ThreadedWSGIServerReloadable(self.interface, self.port, app)
  File "/usr/lib/python3/dist-packages/odoo/service/server.py", line 136, in __init__
    handler=RequestHandler)
  File "/usr/lib/python3/dist-packages/werkzeug/serving.py", line 476, in __init__
    HTTPServer.__init__(self, (host, int(port)), handler)
  File "/usr/lib/python3.5/socketserver.py", line 440, in __init__
    self.server_bind()
  File "/usr/lib/python3/dist-packages/odoo/service/server.py", line 151, in server_bind
    super(ThreadedWSGIServerReloadable, self).server_bind()
  File "/usr/lib/python3.5/http/server.py", line 138, in server_bind
    socketserver.TCPServer.server_bind(self)
  File "/usr/lib/python3.5/socketserver.py", line 454, in server_bind
    self.socket.bind(self.server_address)
OSError: [Errno 98] Address already in use

Does anyone know what is wrong with my debug configuration?

Thanks!!

UPDATE

Perhaps some more information is necessary. I start the odoo-server with a docker-compose file and then with VSCode I remotely attach to that odoo-server. Restarting the server with the odoo-bin command works fine with VSCode terminal.

I have two docker containers running:

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                              NAMES
4ac4a4c8481f        odoo:12.0           "/entrypoint.sh odoo…"   7 days ago          Up 4 minutes        0.0.0.0:8069->8069/tcp, 8071/tcp   odoo-docker_web_1
5910cce38985        postgres:10         "docker-entrypoint.s…"   7 days ago          Up 4 minutes        5432/tcp                           odoo-docker_db_1

And only odoo server is running on 8069:

odoo@4ac4a4c8481f:/mnt/extra-addons$ lsof -i :8069
COMMAND PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
python3   1 odoo    7u  IPv4  44986      0t0  TCP *:8069 (LISTEN)

So probably I am wrong using "launch" request type, because it tries to restart the server. I have also tested this configuration:

{
   "name": "Odoo 12 Attach",
   "type": "python",
   "request": "attach",
   "port": 8069,
   "host": "localhost",           
 },

but then the debugger is terminating immediately without error message.

解决方案

In order to understand how remote debugging works for all python services or apps which based on it such as Odoo, Flask, Django, Web2py or whatever. you have to understand three different concepts the docker container, the debugger, the python app server (in our case it's Odoo). so in many cases, when running Odoo from docker it is like the following image:

and what you really need to be able to debug would be like the following image:

please note the difference:

  • without debugging you have two ports, one internal the other is external which will pass http requests from the browser to Odoo & vice versa. however after debugging you have 4 ports, 2 of them for the http request & the other 2 for debugging information (which is based on json in our case) from Vscode to debugpy & vice versa (you could also use 2 ports by the way).
  • without debugging your entrypoint would be whats defined in the Dockerfile. with debugging, you modify the entrypoint to be debugpy. which will be responsible for running Odoo

czuniga, approach is really good & it is almost the same as following:

works with vscode 1.45.0 & later. for reference files https://gist.github.com/kerbrose/e646aaf9daece42b46091e2ca0eb55d0

1- Edit your docker.dev file & insert RUN pip3 install -U debugpy. this will install a python package debugpy instead of the deprecated one ptvsd because your vscode (local) will be communicating to debugpy (remote) server of your docker image using it.

2- Start your containers. however you will be starting the python package that you just installed debugpy. it could be as next command from your shell.

docker-compose run --rm -p 8888:3001 -p 8879:8069 {DOCKER IMAGE[:TAG|@DIGEST]} /usr/bin/python3 -m debugpy --listen 0.0.0.0:3001 /usr/bin/odoo --db_user=odoo --db_host=db --db_password=odoo

3- Prepare your launcher file as following. please note that port will be related to odoo server. debugServer will be the port for the debug server

{
    "name": "Odoo: Attach",
    "type": "python",
    "request": "attach",
    "port": 8879,
    "debugServer": 8888,
    "host": "localhost",
    "pathMappings": [
        {
            "localRoot": "${workspaceFolder}",
            "remoteRoot": "/mnt/extra-addons",
        }
    ],
    "logToFile": true

这篇关于如何在Docker中调试odoo?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆