PyTorch debugging inside local Docker container with PyCharm
I have a PyTorch program that is designed to run inside a Docker image. I would like to debug using PyCharm Pro 2019.3 (breakpoint, data inspection, etc.) in my local computer (not a remote machine).
I can successfully launch the docker image and execute the program from within PyCharm (my Run configurations use a Docker image I made, not docker-compose or build from Dockerfile). But the Debug button is grayed out.
I am using the remote interpreter inside the docker container:
What am I missing? Do I have the wrong mental model of how debugging should be in this case?
I searched in this forum and the Internet, and I found several tutorials for remote debugging of Flask or Django apps (which have their own run configuration types) or that connected to a remote docker image on another machine or a VM through SSH/SFTP. Ex:
https://blog.jetbrains.com/pycharm/2015/12/using-docker-in-pycharm/#make-pycharm-docker-interpreter
The PyCharm Docker docs don't say anything about actually debugging: https://www.jetbrains.com/help/pycharm/docker.html?keymap=primary_default_for_kde, https://www.jetbrains.com/help/pycharm/run-debug-configuration-docker.html?keymap=primary_default_for_kde#docker_image_run_config
Or do I need to do "remote debugging" from my local machine into the locally run Docker image through port mapping, or through ssh/sftp?
Please sign in to leave a comment.
The problem is that Docker configuration doesn't support debugging in PyCharm. To debug, you should create a regular python run/debug configuration. When you run this configuration, it will use the Docker image configured as Docker interpreter, and bind the project files to the docker container using volume bindings.
Thank you, Andrey! That solved my problem. I am able to debug my code inside a docker container now.
Not sure how to mark this thread as "answered".
No joy for me.
Using a standard run configuration,
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="download_rocket_launches" type="PythonConfigurationType" factoryName="Python" nameIsGenerated="true">
<module name="data-pipelines-with-apache-airflow" />
<option name="ENV_FILES" value="" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="SDK_NAME" value="Remote Python 3.11.7 Docker Compose (scheduler)" />
<option name="WORKING_DIRECTORY" value="" />
<option name="IS_MODULE_SDK" value="false" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/chapter02/dags/download_rocket_launches.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
</component>
When the docker image is running , and I run this runConfiguration, I see the scheduler service starting in the log,
I don't even see where the ‘airflow’ command is given.
(BTW, this is pyCharm #PY-233.11799.298, built on December 11, 2023)
chapter02-scheduler-1 | airflow command error: argument GROUP_OR_COMMAND: invalid choice: '/usr/local/bin/python3' (choose from 'cheat-sheet', 'config', 'connections', 'dag-processor', 'dags', 'db', 'info', 'jobs', 'kerberos', 'plugins', 'pools', 'providers', 'roles', 'rotate-fernet-key', 'scheduler', 'standalone', 'sync-perm', 'tasks', 'triggerer', 'users', 'variables', 'version', 'webserver'), see help above.
Hi, Jim Katz ! Would you please elaborate? What doesn't work as expected? How is it related to debugging question in this thread?