'Select interpreter of docker container in the vscode

In vscode, we can install the python extension, then select the interpreter which we want, like python in the conda environment.

So we can use "shift" + "enter" key for running the code line by line in the terminal. For managing different virtual environment, using docker container is a better way.

If I already install the docker, and pull the python image. How to select the interpreter which is created in the docker container? Not just remote to the docker container.



Solution 1:[1]

inside your devcontainer.json file that vscode created you have the image key and its value is the route to the image, if you want to use to change the python version you can do so there or using the quick instructions in vscode docs here

Solution 2:[2]

I think it's impossible, I am afraid you must remote to the docker container.

I really can't imagine out you taking a python interpreter in Linux to work on windows directly.

Solution 3:[3]

If your objective is to have vscode to work on a local project and run it with a docker-based interpreter, the solution is: mounting the local project directory to the docker container that contains the interpreter, then in vscode open the project directory (mounted) from the container.

How to mount your project directory:

docker run -v /user/localproject:/root/mountedproject

https://docs.docker.com/storage/volumes/

I have tested it. It should work.

Solution 4:[4]

  1. Install the Python extension
  2. Install the Remote-Containers extension
  3. Open the Command Palette and type Remote-Containers: Attach to Running Container..., then select the running Docker container
  4. VSCode will restart and reload
  5. On the Get Started page, click the Open... and enter the path to the Docker volume mounted to your source code, e.g. /app
  6. Install the Python extension on the container
  7. Install the Docker extension on the container
  8. Open the Command Palette and type Python: Select Interpreter, then select the Docker interpreter
  9. Open the Command Palette and type Python: Configure Tests, then select the framework you use

Source: https://dev.to/alvarocavalcanti/setting-up-a-python-remote-interpreter-using-docker-1i24

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Noam Yizraeli
Solution 2 Steven-MSFT
Solution 3 CyberPlayerOne
Solution 4