For those using Visual Studio Code on Windows 10 Describes how to debug a Python program by remotely connecting to a Docker container in a WSL2 environment. Please check another site in advance for how to use docker desktop in the WSL2 environment and set it up. In addition, install Remote Development with the Visual Studio Code extension. See below for Remote Development. VS Code Remote Development
Now that we're ready, let's get down to the main topic. First, launch VS Code and click on this mark at the bottom left. Then you will see a lot of * Remote -... * at the top. Select * remote-containers open folder in container * Select the desired project folder. At the first startup, you will be asked which setting to refer to when launching the container, so select * docker-compose.yml *, for example. Then, the container will be launched according to the setting, VS Code will connect to the container remotely, and the target folder will be displayed in the left pane. I referred to the following. Developing inside a Container
Opened in VS Code-in the terminal (bottom right by default)
cat /etc/*release
Please enter something like and check the OS version. The OS specified in the Dockerfile is running (^^ ♪
Then select the Python program you want to launch from the left pane. Then, the following message will be displayed at the bottom right, so install as recommended. Click * Dev Container: Existing ... *, and then click [Reload required].
After that, you can select the Python program, set a BreakPoint, execute debugging with ** F5 **, and stop with BreakPoint.
When quitting, select this mark and select End Remote Connection.
It seems that the container itself does not end, so at the moment it seems that you have to drop it by yourself with * docker-compose down *. Also, when the container is brought down, it seems that the above * Python extension for Visual Studio Code * must be installed every time as an extension of Visual Studio Code. (Investigation required)
As a result, we can expect a significant improvement in development efficiency, and above all, we can feel reassured that we can work inside the container.
Recommended Posts