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.

Answer from Elton Stoneman on Stack Overflow
Top answer
1 of 3
15

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.

2 of 3
3

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
}
🌐
Docker
docker.com › blog › containerized-python-development-part-3
Containerized Python Development - Part 3 | Docker
November 21, 2024 - We take as an example again our Flask application. When running in debug mode, aside from the reloader module it also includes an interactive debugger. Assume we update the code to raise an exception, the Flask service will return a detailed response with the exception. Another interesting case to exercise is the interactive debugging where we place breakpoints in the code and do a live inspect. For this we need an IDE with Python and remote debugging support.
Discussions

Python Docker Remote Debugging VS Code - Stack Overflow
trying to get remote debugging for my python flask API I have. I'm able to docker-compose up and have postman successfully call the running container, but when I try to attach the debugger, it never More on stackoverflow.com
🌐 stackoverflow.com
python - PyCharm remote debug in a docker container - Stack Overflow
I'm having an hard time trying to figure out how to setup a remote debug of a python app (Flask) running in a Docker container. Specifically I'm using docker-compose, PyCharm professional and pytho... More on stackoverflow.com
🌐 stackoverflow.com
Debugging dockerized Python apps in VSCode
I find it easiest to just call breakpoint() in my code and use the docker attach command to drop into the command line debugger. No extra setup. And you can improve the command line experience with pdbpp or ipdb. More on reddit.com
🌐 r/Python
20
126
December 23, 2023
Can Pycharm be run from INSIDE a docker container?
I'm sure there is a way to open a port on the interpreter to connect a debugger. Just not sure what it is off the top of my head. You just need to make sure that the correct command is run inside the container, and that the correct port is forwarded from the host machine. Edit: This may help - https://www.jetbrains.com/help/pycharm/remote-debugging-with-product.html More on reddit.com
🌐 r/pycharm
19
8
May 18, 2021
🌐
Visual Studio Code
code.visualstudio.com › docs › containers › debug-python
Debug Python within a container
November 3, 2021 - Here is an example of using dockerServerReadyAction to launch the browser to open the about.html page based on a specific server message pattern: { "configurations": [ { "name": "Containers: Python - Django", "type": "docker", "request": "launch", "preLaunchTask": "docker-run: debug", "python": { "pathMappings": [ { "localRoot": "${workspaceFolder}", "remoteRoot": "/app" } ], "projectType": "django" }, "dockerServerReadyAction": { "action": "openExternally", "pattern": "Starting development server at (https?://\\S+|[0-9]+)", "uriFormat": "%s://localhost:%s/about.html" } } ] }
🌐
GitHub
github.com › DonJayamanne › vscode-python-samples › tree › master › remote-debugging-docker
vscode-python-samples/remote-debugging-docker at master · DonJayamanne/vscode-python-samples
Type the following command in the terminal window docker run -it -p 3000:3000 remote-debugging-docker · Confirm the following is displayed in the terminal window Waiting to attach · This step will ensure you have setup the program to be debugged ...
Author   DonJayamanne
🌐
Martin Heinz
martinheinz.dev › blog › 99
Remote Interactive Debugging of Python Applications Running in Kubernetes | Martin Heinz | Personal Website & Blog
June 19, 2023 - # debugger.Dockerfile FROM python:3.11.4-slim-buster RUN apt-get update && apt install -y gdb RUN pip install debugpy ENV DEBUGPY_LOG_DIR=/logs
🌐
GitHub
github.com › paloukari › python-docker-remote-debugging
GitHub - paloukari/python-docker-remote-debugging · GitHub
This is a simple example to demonstrate how to do Python remote debugging running in a Docker container, in VS Code.
Author   paloukari
Top answer
1 of 1
4

I finally got it working with remote debugging. I had to pip3 install ptvsd==3.0.0 on my local, and make sure that the requirements.txt for my docker container had the same version. (note: the latest version 3.2.1 didn't work)

@BrettCannon had the right link for a good tutorial https://code.visualstudio.com/docs/python/debugging#_remote-debugging

What I had to do was add some code to the app.py of the flask app. I originally was getting address already in use error when starting the container, so I added the socket code and after the first successful attach of debugger I didn't seem to need it anymore (strange I know, but that's why I left it in in case someone else gets that error)

try:
    import ptvsd
    # import socket
    # sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    # sock.close()
    ptvsd.enable_attach(secret=None,address=('0.0.0.0',5050))
    ptvsd.wait_for_attach()
except Exception as ex:
    print('Not working: ')

also i took the debug kwarg off the app.run() in app.py for the flask app. This all gave me the ability to connect the debugger, but the breakpoints where "Unverified", so the last thing that had to happen was a path to the app.py in the launch.json for the remoteRoot. I will say I created a small test api to get this working, and it only need the first level of pathing (ie. /app and not /app/app/app.py)Here is a github of the test api I made (https://github.com/tomParty/docker_python). So if the debugger is attaching, but your breakpoints are unverified, play around with the path of the remoteRoot

"remoteRoot": "/nomz/nomz/app.py"
Find elsewhere
🌐
Bell-sw
docs.bell-sw.com › alpaquita-linux › latest › containers › remote-debug
Remote debugging applications running in Docker remotely, with JetBrains and VSCode: Java, C, and Python
Although this document covers remote ... PyCharm uses pydevd-pycharm and VSCode uses debugpy for Python by default. Adjust or create a Docker image that exposes the debugging server over a network....
🌐
pythontutorials
pythontutorials.net › blog › how-to-remote-debug-python-code-in-a-docker-container-with-vs-code
How to Remote Debug Python Code in a Docker Container with VS Code: Step-by-Step Guide — pythontutorials.net
To containerize the app, we need a Dockerfile. This file defines the environment, dependencies, and how to run the app. Critical for debugging: We’ll install debugpy—the Python package that enables remote debugging via VS Code.
🌐
Vinta
vinta.ws › code › remotely-debug-a-python-app-inside-a-docker-container-in-visual-studio-code.html
Remotely debug a Python app inside a Docker container in Visual Studio Code – I Failed the Turing Test
February 24, 2018 - Your Python app communicates with those services through ports which exposed to 127.0.0.1. Therefore, you could just use VS Code's debugger without strange tricks. In practice, it is okay that your local development environment is different from the production environment. # docker-compose.yml version: '3' services: db: image: mongo:3.6 ports: - "27017:27017" volumes: - mongo-volume:/data/db cache: image: redis:4.0 ports: - "6379:6379"
🌐
Python Engineer
python-engineer.com › posts › debug-python-docker
How to debug Python apps inside a Docker Container with VS Code - Python Engineer
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "Python: Remote Attach", "type": "python", "request": "attach", "connect": { "host": "localhost", "port": 5678 }, "pathMappings": [ { "localRoot": "${workspaceFolder}", "remoteRoot": "." } ], "justMyCode": true } ] } You can now set breakpoints and then click on Run -> Start Debugging to start the debugging session. Enjoy! ... This works with VS Code when running it on the host machine, but you can also connect VS Code to your running container and debug inside the container! Article: Debugging for Dockerized ML applications in Python
🌐
Towards Data Science
towardsdatascience.com › home › latest › debugging for dockerized ml applications in python
Debugging for Dockerized ML applications in Python | Towards Data Science
November 25, 2024 - What worked best in the end for me is a debugger that can connect to a Docker container where your model training application is running, and directly inspect the environment of a given Python script. This is where debugpy comes in! Previously known as ptvsd, this package is developed by Microsoft specifically for use in VSCode with Python. It implements all of the common debugging tools you would expect, as well as allowing for attaching to remote environments, such as Docker containers or even remote machines via SSH.
🌐
Reddit
reddit.com › r/python › debugging dockerized python apps in vscode
r/Python on Reddit: Debugging dockerized Python apps in VSCode
December 23, 2023 -

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/

🌐
Andrewwhipple
andrewwhipple.com › blog › 2023 › 02 › 07 › debug-python-in-vs-code
How To Debug Docker-ized Python Apps in Visual Studio Code
February 7, 2023 - This creates a command for VS Code called "Attach (remote debug)" that will tell it to attach a python debugger to 127.0.0.1:5678. If you've been paying attention, that should mean the debugger is now attaching to the port exposed by the application container that is being listened to by debugpy. Run docker...
🌐
Debuglab
debuglab.net › home › 2025 › october › 12 › mastering remote debugging: a comprehensive guide for modern developers
Mastering Remote Debugging: A Comprehensive Guide for Modern Developers - Debuglab | Debugging, Profiling & Error Hunting
December 28, 2025 - Remote debugging truly shines when dealing with modern, distributed architectures like containers and microservices. When your Node.js or Python application is running inside a Docker container, the principles are the same, but you need to handle port mapping. You must expose the debug port from the container to the host machine. Here’s a docker-compose.yml example for our Node.js application that forwards the host’s port 9229 to the container’s port 9229.
🌐
KDnuggets
kdnuggets.com › debugging-python-in-docker-a-tutorial-for-beginners
Debugging Python in Docker: A Tutorial for Beginners - KDnuggets
August 20, 2025 - IDE's debugger directly to code running inside a Docker container. This gives you the full power of your IDE's debugging tools. ... FROM python:3.11-slim WORKDIR /app # Install the remote debugging library RUN pip install debugpy COPY app.py ...
🌐
DEV Community
dev.to › sidpalas › debugging-docker-containers-3cgj
How to Debug Docker Containers (Python + VSCode) - DEV Community
July 20, 2020 - 1) Override the entrypoint at runtime and exec into the container 2) Copy files into or out of the container for inspection/comparison 3) Run a remote debugger inside the container and attach to it over the network · I created a video walking ...
🌐
GitHub
github.com › isaacbernat › docker-pudb
GitHub - isaacbernat/docker-pudb: Debug Python code within a Docker container remotely from your terminal using pudb
Debug Python code within a Docker container remotely from your terminal using pudb - isaacbernat/docker-pudb
Starred by 26 users
Forked by 2 users
Languages   Python 76.4% | Dockerfile 23.6% | Python 76.4% | Dockerfile 23.6%