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 bedebugpy
. which will be responsible for running Odoo
so to debug Odoo you will be doing as following:
-
Edit your
docker.dev
file & insertRUN pip3 install -U debugpy
. this will install a python packagedebugpy
instead of the deprecated oneptvsd
because your vscode (local) will be communicating with debugpy (remote) server of your docker image using it.- Start your container. you will be starting the python package that you just installed
debugpy
. it could be as next command from your shell.
- Start your container. you will be starting the python package that you just installed
docker-compose run --rm -p 8888:8888 -p 8869:8069 {DOCKER IMAGE[:TAG|@DIGEST]} /usr/bin/python3 -m debugpy --listen 0.0.0.0:8888 /usr/bin/odoo --db_user=odoo --db_host=db --db_password=odoo
- 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": 8869,
"debugServer": 8888,
"host": "localhost",
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "/mnt/extra-addons",
}
],
"logToFile": true
}
Top comments (6)
Hi Khaled, thank you for your post. It was a great help to start understanding how to debug my Odoo application.
I'm new to Docker & Docker compose and I'm struggling to get Debugpy to work with Odoo and VS code. I'm using a docker-compose file that runs Odoo fronted by Nginx.
Debugpy is already installed in the container but I'm can't see how I can run my container with both Odoo & Nginx "wrapped" by Debugpy.
In your post, I cannot see how the command :
docker-compose run --rm -p 8888:8888 -p 8869:8069 {DOCKER IMAGE[:TAG|@DIGEST]} .....
applies to my case. My docker-compose is running both Odoo & Nginx and I would like to be able to debug with this configuration in VS code.
Would you have any advice?
Thanks!
Farid
Hello Farid
please note that when using debugpy to debug python apps (Odoo server in our case). you're overriding the entrypoint.sh of the container. by other words you are starting the debugpy server inside of the container instead of Odoo server.
take a look at the following command:
/usr/bin/python3 -m debugpy
: here you ask python to start module debugpy--listen 0.0.0.0:8888
: here you aske debugpy server to listen 0.0.0.0:8888/usr/bin/odoo
: here you ask debugpy to start a python process (in our case odoo server)--db_user=odoo --db_host=db --db_password=odoo
: here, are the rest of odoo cliso if you are debugging a different python file named tic_tac_toe.py, the command would be something like
the first portion of the docker-compose command:
it is asking docker-compose to map ports of the host to ports of the container & running the image. please note that you have to replace
{DOCKER IMAGE[:TAG|@DIGEST]}
with image information. you can get such information from commanddocker images -a
so in my case it could be
Hi Khaled,
Thanks so much for your post. It was very helpful and I was able to debug my odoo setup in docker.
There's one issue I'm struggling with and I was hoping you can help me with it. In my Odoo setup, I have enabled multiprocessing with several workers in order to get livechat working. Unfortunately, this causes all workers to reach virtual memory limit and crash, when docker is started with debugpy entrypoint. So I'm not able to debug livechat issues. Is there a way to enable debugpy to work with odoo multiple workers?
Thanks again
this may help
github.com/microsoft/debugpy/blob/...
or
code.visualstudio.com/docs/python/...
Hi Khaled, Thank you for your post. It's help me to start and understanding how to use VSC to debug my Odoo Custom Applications.
But how to debug odoo's native mods?
For example debugy sale module action_confirm()。
docker cp container_id:/usr/lib/python3/dist-packages/odoo odoo/.
It's error:
invalid symlink "/Users/jason/docker/odoo14/odoo/odoo/odoo/addons/point_of_sale/static/src/fonts/Inconsolata.otf" -> "../../../../../../../../../share/fonts/truetype/inconsolata/Inconsolata.otf"
Nice article, Keep it up!