2

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: pgadmin4@pgadmin.org
      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
Community
  • 1
  • 1
Moaz Mabrok
  • 697
  • 10
  • 32
  • Similar question at [odoo forum](https://www.odoo.com/fr_FR/forum/aide-1/question/how-debug-code-from-visual-studio-code-in-docker-container-158277) – Kenly May 17 '20 at 07:07
  • I tried `ptvsd` but it broke my container and was not able to run it to remove the edit@Kenly – Moaz Mabrok May 17 '20 at 07:11
  • also using the extension I will not need to edit the container making it easier to work with many container if needed @Kenly – Moaz Mabrok May 17 '20 at 07:14
  • You can check the version with [debugpy](https://stackoverflow.com/questions/57626427/how-to-debug-odoo-in-docker#answer-61765150). Sorry I can't check the configuration on MAC. – Kenly May 17 '20 at 12:55

1 Answers1

2

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
}
kerbrose
  • 1,095
  • 2
  • 11
  • 22