Using Python linters with Docker in VS Code Using Python linters with Docker in VS Code python python

Using Python linters with Docker in VS Code


Not the Docker side, just some VS code considerations

VS Code relies on two mechanisms for resolving python highlighing: environment and linter.

For environment you can check https://code.visualstudio.com/docs/python/environments, which basically says either python is availsble on the system in path, or pick virtual environmrnt you create, or provide a path to python executable in json.

https://code.visualstudio.com/docs/python/linting tells to install linter with pip, runnable from environment you configured or provide a path to linter in json.

So it looks the only things you need to replicate VSCode python linting is python executabe, installation of pylint and json configuration for vscode.


I've accomplished this using the Remote - Containers extension for VS Code. The steps i followed were:

  1. Install the Remote Containers extension https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers

  2. Open the Command Pallette (cmd + shift + p in Mac OS) and type Remote-Containers, then select the option "Attach to Running Container"

  3. Select the running container (where the python interpreter and code are)

  4. Click in the bottom bar where the python interpreter is displayed (git branch and current container also are displayed in this bar)

  5. When you get prompted which interpreter to use select "Enter interpreter path..." option and select the python path, the most common case will be /usr/local/bin/python

Now VS code is using the same interpreter as your docker container and you can install the linter you want to, in my case flake8