Yes, this is possible - when the Python app is running in a Docker container, you can treat it like a remote machine.
In your Docker image, you'll need to make the remote debugging port available (e.g. EXPOSE 3000 in the Dockerfile), include the ptvsd setup in your Python app, and then publish the port when you run the container, something like:
docker run -d -p 3000:3000 my-image
Then use docker inspect to get the IP address of the running container, and that's what you use for the host in the launch file.
Yes, this is possible - when the Python app is running in a Docker container, you can treat it like a remote machine.
In your Docker image, you'll need to make the remote debugging port available (e.g. EXPOSE 3000 in the Dockerfile), include the ptvsd setup in your Python app, and then publish the port when you run the container, something like:
docker run -d -p 3000:3000 my-image
Then use docker inspect to get the IP address of the running container, and that's what you use for the host in the launch file.
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
}
Debugging dockerized Python apps in VSCode
Python Docker Remote Debugging VS Code - Stack Overflow
python - PyCharm remote debug in a docker container - Stack Overflow
Anyone has a python remote (docker) debugger setup?
Videos
Finally, set aside the time to configure VScode debugger to peek into web apps running inside docker containers.
I use the debugger with pretty much everything but containers. Not sure why I didn’t bother to do it earlier. Huge productivity boost. TIL:
https://rednafi.com/python/debug_dockerized_apps_in_vscode/
Use host.docker.internal instead of 0.0.0.0. This will allow docker to decide which IP to use.
Use a remote interpreter, this will solve a couple of issues at once. I already answered this here Rich editors in a Docker development environment
Add a remote python SDK to your IDE, this will then also resolve all the libraries being installed remotely. You will require an SSH connection to get this done though, so install sshd and use the shared developer key I outlined in my answer.
Even though this now a bit more effort, I will give you a lot better results, also in the other sections you did not yet encounter and will find, when doing just a remote-port connection.
If you still want to use the port-based debugging, see Docker: MacOSX Expose Container ports to host machine - this explains how you should understand the attach and the listen part.