DEV Community

Khaled Said
Khaled Said

Posted on

How to remote debugging Odoo Docker images (Python based framework)

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:
enter image description here

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

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

so to debug Odoo you will be doing as following:

  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 with debugpy (remote) server of your docker image using it.

    1. Start your container. 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: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
  1. 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
}

Oldest comments (6)

Collapse
 
captainmoha profile image
Mohamed A. Farouk

Nice article, Keep it up!

Collapse
 
farido profile image
Farid-O

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

Collapse
 
kerbrose profile image
Khaled Said

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 --listen 0.0.0.0:8888 /usr/bin/odoo --db_user=odoo --db_host=db --db_password=odoo
Enter fullscreen mode Exit fullscreen mode

/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 cli
so if you are debugging a different python file named tic_tac_toe.py, the command would be something like

python -m debugpy tic_tac_toe.py
Enter fullscreen mode Exit fullscreen mode

the first portion of the docker-compose command:

docker-compose run --rm -p 8888:8888 -p 8869:8069 {DOCKER IMAGE[:TAG|@DIGEST]}
Enter fullscreen mode Exit fullscreen mode

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 command docker images -a

~ → docker images -a
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
odoo         14        27c34e85682c   2 weeks ago   1.24GB
odoo         14.0      27c34e85682c   2 weeks ago   1.24GB
postgres     13        a6cd86e1dfce   3 weeks ago   314MB
Enter fullscreen mode Exit fullscreen mode

so in my case it could be

docker-compose run --rm odoo:13
# or 
docker-compose run --rm a6cd86e1dfce
Enter fullscreen mode Exit fullscreen mode
Collapse
 
kshaheen profile image
kshaheen

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

Collapse
 
kerbrose profile image
Collapse
 
jaronemo profile image
Jason

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"