Moaz  Mabrok
Moaz Mabrok

Reputation: 740

How to use VS code debugger with odoo in a docker container [vs code + odoo + docker + mac]

Hi this is somewhat similar to this question but nothing there about docker containers

I am using a mac so I started using docker since it's more convenient on macOS Microsoft visual studio code has may feature a full development environment

It has an extension from MS Remote - Containers with should make easier

This is my docker-compose.yml

version: '2'
services:
  db:
    image: 'postgres:11'
    environment:
      - POSTGRES_PASSWORD=odoo
      - POSTGRES_USER=odoo
      - POSTGRES_DB=postgres
    restart: always
    volumes:
      - './postgresql:/var/lib/postgresql/data'
  pgadmin:
    image: dpage/pgadmin4
    depends_on:
      - db
    ports:
      - '5555:80'
    environment:
      PGADMIN_DEFAULT_EMAIL: [email protected]
      PGADMIN_DEFAULT_PASSWORD: admin
    volumes:
      - './pgadmin:/var/lib/pgadmin'
  odoo13:
    image: 'odoo:13'
    depends_on:
      - db
    ports:
      - '10013:8069'
    tty: true
    command: '-- --dev=reload'
    volumes:
      - './addons:/mnt/extra-addons'
      - './enterprise:/mnt/enterprise-addons'
      - './config:/etc/odoo'
    restart: always

can you please help or share a better way to run odoo with debugger on mac

Thank you in advance

Upvotes: 3

Views: 3408

Answers (1)

kerbrose
kerbrose

Reputation: 1185

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.

  2. 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
}

Upvotes: 3

Related Questions