Run and debug python script inside docker container with VS Code

474 views Asked by At

I have below command to run my python file inside docker container:

docker run --rm --name=my_container --volume "/my_dir/:/host:z" myimage:latest python /host/api/my_file.py 

I want to run it with VS code debug mode.

I tried looking at tutorials from VS code and Docker but most of the instructions are for Django/Flask and I don't understand how to modify it.

1

There are 1 answers

0
MingJie-MSFT On

We can use command to create a Docker launch configuration to build and run your container in debug mode.Docker: Add Docker Files to Workspace...

  1. Navigate to the file that contains your app's startup code, and set a breakpoint.
  2. Navigate to Run and Debug and select Docker: Python - General, Docker: Python - Django, or Docker: Python - Flask, as appropriate.
  3. Start debugging using the F5 key.

You can also refer to this document for more details about docker and debug in docker