How to debug a Python program by remotely connecting to a Docker container in WSL2 environment with VS Code

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. image.png 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. image.png 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. image.png

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

How to debug a Python program by remotely connecting to a Docker container in WSL2 environment with VS Code
Build a Python environment with WSL + Pyenv + Jupyter + VS Code
I tried to build an environment with WSL + Ubuntu + VS Code in a Windows environment
Try to create a python environment with Visual Studio Code & WSL
Create a simple Python development environment with VS Code and Docker
How to build Python and Jupyter execution environment with VS Code
I was addicted to creating a Python venv environment with VS Code
Steps to create a Python virtual environment with VS Code on Windows
Use Python in Anaconda environment with VS Code
Build a python execution environment with VS Code
Build a development environment using Jupyter and Flask with Python in Docker (supports both VS Code / code-server)
How to convert / restore a string with [] in python
How to build a Django (python) environment on docker
How to make a Python package using VS Code
Debug Python with VS Code
[Django] Use VS Code + Remote Containers to quickly build a Django container (Docker) development environment.
How to use VS Code in venv environment on windows
How to develop in a virtual environment of Python [Memo]
How to implement Python EXE for Windows in Docker container
How to build a python2.7 series development environment with Vagrant
Run the program without building a Python environment! !! (How to get started with Google Colaboratory)
How to delete a Docker container
Create a Python (Django) learning environment with Docker so that you can debug with VS Code (almost your own procedure memo)
Create a Python environment for professionals in VS Code on Windows
How to batch start a python program created with Jupyter notebook
How to debug Dash (Flask) in Docker + VSCode + remote connection environment
How to create a heatmap with an arbitrary domain in Python
Debug settings in virtual environment when using Pipenv with VS Code
Create a C ++ and Python execution environment with WSL2 + Docker + VSCode
[Windows 10] [Development environment construction] How to resolve when unresolved import'django.xxx' python (unresolved-import) occurs in VS Code
How to access environment variables in Python
How to work with BigQuery in Python
How to get a stacktrace in python
How to install python3 with docker centos
Prepare a Python virtual environment for your project with venv with VS Code
How to install python package in local environment as a general user
How to make a container name a subdomain and make it accessible in Docker
Environment maintenance made with Docker (I want to post-process GrADS in Python
How to use VS Code (code server) with Google Colab in just 3 lines
How to sort by specifying a column in the Python Numpy array.
How to stop a program in python until a specific date and time
How to deal with old Python versions in Cloud9 made by others
How to read a CSV file with Python 2/3
How to generate a QR code and barcode in Python and read it normally or in real time with OpenCV
How to create a Python virtual environment (venv)
How to clear tuples in a list (Python)
How to embed a variable in a python string
Flutter in Docker-How to build and use a Flutter development environment inside a Docker container
How to create a JSON file in Python
How to drop Google Docs in one folder in a .txt file with python
Python (Windows 10) Virtual Environment / Package with VS Code
Create a virtual environment with conda in Python
Debug with VS Code using boost python numpy
[Python] Build a Django development environment with Docker
How to notify a Discord channel in Python
How to use tkinter with python in pyenv
Work in a virtual environment with Python virtualenv.
Python local development environment construction template [Flask / Django / Jupyter with Docker + VS Code]
How to run GUI programs such as tkinter in Python environment on WSL2
Easy Python data analysis environment construction with Windows10 Pro x VS Code x Docker
How to run a Django application on a Docker container (development and production environment)