You have to configure the debugger with: debugpy.listen(("0.0.0.0", 5678)).

This happens because, by default, debugpy is listening on localhost. If you have your docker container on another host you have to add 0.0.0.0.

Answer from Wason1797 on Stack Overflow
🌐
Python Engineer
python-engineer.com › posts › debug-python-docker
How to debug Python apps inside a Docker Container with VS Code - Python Engineer
This article shows how you can can use a debugger in VS Code to debug Python apps inside a Docker Container. ... First, we need to add debugpy.
Discussions

Cannot attach Python debugger to debugpy within a future inside Docker container
Python code executing inside a Docker container (also Linux image, w/ Python 3.9.10) Trying to set a debugpy breakpoint inside a future and attach a debugger to the process inside the container More on github.com
🌐 github.com
3
November 20, 2023
How to remote debug python code in a Docker Container with VS Code - Stack Overflow
I'm using this to start my docker (zope based application) sudo docker run -it -p 8080:8080 -v ... /usr/bin/python3 -m debugpy I got /usr/bin/python3: No module named debugpy under Ubuntu 2021-01-31T21:34:57.667Z+00:00 More on stackoverflow.com
🌐 stackoverflow.com
Can't connect to host if the docker-compose is created as a pre launch task
version: '3' services: backend: image: backend build: context: . dockerfile: ./Dockerfile command: [ "sh", "-c", "pip install debugpy -t /tmp && python /tmp/debugpy --wait-for-client --listen 0.0.0.0:5678 manage.py runserver 0.0.0.0:8000" ] ports: - 8000:8000 - 5678:5678 volumes: - ./:/app/ More on github.com
🌐 github.com
3
June 8, 2022
Running a Python debugger in a Docker Image - Stack Overflow
docker run -p 5678:5678 CONTAINERNAME python3 /home/init.py · It hangs and times out on the Visual Studio side. In the video, he uses this to run the python unittest module, which is why I tried taking out the -m from the end of the command in my modified version. However, it looks like debugpy ... More on stackoverflow.com
🌐 stackoverflow.com
People also ask

What is Debugpy?
Debugpy is a Python debugger that integrates seamlessly with VS Code and other IDEs, allowing developers to debug Python scripts and applications efficiently.
🌐
debugpy.com
debugpy.com
Debugpy – Fast & Efficient Python Debugging Tool
Which Python versions does Debugpy support?
Debugpy supports Python 3.6 and above.
🌐
debugpy.com
debugpy.com
Debugpy – Fast & Efficient Python Debugging Tool
Does Debugpy support multi-threaded debugging?
Yes, it can debug multi-threaded Python applications, but some features may have limitations.
🌐
debugpy.com
debugpy.com
Debugpy – Fast & Efficient Python Debugging Tool
🌐
Visual Studio Code
code.visualstudio.com › docs › containers › debug-python
Debug Python within a container
November 3, 2021 - How to configure and troubleshoot debugging of Python apps running in a container, using Visual Studio Code.
🌐
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!
🌐
YouTube
youtube.com › watch
Debug Python inside Docker using debugpy and VSCode - YouTube
We will debug python inside docker using debugpy and VSCode#python #debugpy #vscode #docker #linux #debugging #python3 #programming #code #commandline #visua...
Published   June 12, 2022
Find elsewhere
🌐
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 - I couldn't find anything to clearly ... So, that's what this is! It works! Maybe there's a better way, but this is My Way! debugpy is the Python debugging tool that VS Code uses, so you need to make sure it's installed on the container that will run the application....
🌐
debugpy
debugpy.com
Debugpy – Fast & Efficient Python Debugging Tool
Debugpy – Fast & Efficient Python Debugging Tool
Debugpy makes it possible to debug applications running on remote systems, including servers and containers such as Docker. Debugpy is a lightweight Python debugger that helps developers inspect code, set breakpoints, and troubleshoot in real time with ease. #Debugpy
Rating: 4.5 ​
🌐
Plain English
python.plainenglish.io › python-debugging-running-or-dockerized-application-807eaee009cc
How to Debug Running or Dockerized Python Apps | by alpha2phi | Python in Plain English
January 6, 2021 - In my previous article on Serving ... — Containers extension. In this article I will go deeper on how to debug a running or Dockerized Python app. I am going to use the debugpy library which can be installed via pip....
🌐
GitHub
github.com › microsoft › debugpy › issues › 1465
Cannot attach Python debugger to debugpy within a future inside Docker container · Issue #1465 · microsoft/debugpy
November 20, 2023 - If you run it on the host Linux VM (outside Docker container), and change "host" to "localhost", it works fine.
Author   sebastko
🌐
Medium
pavolkutaj.medium.com › how-to-debug-python-scripts-running-in-docker-container-e300982a516e
How to Debug Python Scripts running in Docker Container | by Pavol Z. Kutaj | Medium
September 27, 2022 - docker run --rm -it ` --name "<container_name>" ` -v "<host_repo_path>:<container_repo_path>" ` -e LANG='en_US.UTF-8' ` -e PYTHONIOENCODING='UTF-8' ` -e PYTHONPATH="<container path to dependencies>" ` -p 5678:5678 ` -w $project_container_folder ` <docker image> NOTE: I am also activating debugger logging to files, see https://github.com/microsoft/debugpy/wiki/Enable-debugger-logs for more
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
}
🌐
Rednafi
rednafi.com › python › debug_dockerized_apps_in_vscode
https://rednafi.com/python/debug-dockerized-apps-in-vscode/
December 22, 2023 - Hi, I'm Redowan Delowar—A software engineer with a flair for words and wires.
🌐
KDnuggets
kdnuggets.com › debugging-python-in-docker-a-tutorial-for-beginners
Debugging Python in Docker: A Tutorial for Beginners - KDnuggets
August 20, 2025 - # Expose the port that the debugger will use EXPOSE 5678 # Start the program with debugger support CMD ["python3", "-m", "debugpy", "--listen", "0.0.0.0:5678", "--wait-for-client", "app.py"] ... EXPOSE 5678 tells Docker that our container will use port 5678.
🌐
GitHub
github.com › microsoft › debugpy › issues › 954
Can't connect to host if the docker-compose is created as a pre launch task · Issue #954 · microsoft/debugpy
June 8, 2022 - version: '3' services: backend: image: backend build: context: . dockerfile: ./Dockerfile command: [ "sh", "-c", "pip install debugpy -t /tmp && python /tmp/debugpy --wait-for-client --listen 0.0.0.0:5678 manage.py runserver 0.0.0.0:8000" ] ports: - 8000:8000 - 5678:5678 volumes: - ./:/app/
Author   yogaxpto
🌐
Rednafi
rednafi.com › home › python › debugging dockerized python apps in vscode
Debugging dockerized Python apps in VSCode | Redowan's Reflections
December 22, 2023 - # docker-compose.debug.yml version: "3.9" services: web: build: context: . dockerfile: ./Dockerfile command: - "sh" - "-c" - | pip install debugpy -t /tmp \ && python /tmp/debugpy --wait-for-client --listen 0.0.0.0:5678 \ -m uvicorn main:app --host 0.0.0.0 --port 8000 ports: - 8000:8000 - 5678:5678
🌐
Amit Chaudhary
amitness.com › notes › debugpy
How to use debugpy in VSCode - Amit Chaudhary
April 2, 2025 - python -m debugpy --listen 0.0.0.0:5678 --wait-for-client \ -m uvicorn main:app --host 0.0.0.0 --port 8000 · I’m demonstrating this locally, but you can run the same command inside a Docker container or on a remote server.
🌐
DEV Community
dev.to › ferkarchiloff › how-to-debug-django-inside-a-docker-container-with-vscode-4ef9
How to debug Django inside a Docker container with VSCode - DEV Community
January 26, 2024 - At the same level of docker-compose.yml, create a new file called docker-compose.debug.yml. It should have the service you need to debug, as also the ports and command. It must have the same port used for the application and debug port defined. ... version: "3.7" services: app: ports: - "8000:8000" - "5678:5678" command: ["sh", "-c", "python3 -m debugpy --listen 0.0.0.0:5678 manage.py runserver 0.0.0.0:8000"]
🌐
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/