I followed the docker-compose tutorial to be able to debug my application. That works. However when I change the source code in the PyCharm text editor, Stop and Debug main.py again, the breakpoints are out of sync: the description in the Debug frame stack doesn't match with where execution is being shown in the text editor.
My application is ran as a docker-compose, and I am trying to debug one of the services. The application structure is like:
The Dockerfile does a copy of the source code
COPY /service1/service1_src /service1_src
and when I use PyCharm > Services > Docker > Docker-compose: my_app > service1 > /SERVICE1
and look at the Files, I see the code in both /service1_src and /opt/project/my_app/service1/service1_src.
I have a feeling I need to setup Path Mappings, but I am not sure what and where.
There are three places where a copy of my source code lives:
- on my host PC filesystem where the PyCharm project is
- in the Docker container at /service1_src
- in the Docker container at /opt/project/my_app/service1/service1_src
There are three places I see that I can enter mappings:
- File > Settings > Build, Execution, Deployment > Docker > Path mappings
- File > Settings > Project: > Python Interpreter > Path mappings
- Run/Debug Configurations > Python > main > Configuration > Path mappings
One thing I have found that works is to delete the Services > Docker > Images > service1:latest whenever I make changes that moves the source to different line numbers, but that seems like a slow process.
Does anyone have any suggestions on how to best have the local source changes be seen when debugging in the container?
PyCharm 2021.2.2 on Windows 10, Docker Desktop 4.0.1