I'm trying to make Python linters to work in VS Code when Python and all packages are installed in a Docker container.
I didn't use linters before. But as far as I understand how linters work (at least in VS Code), I need to point VS Code to Python interpreter and set paths to packages if needed. And this becomes a problem if everything is installed in Docker container.
I'm trying to use only Docker features. What I came up with is the following:
- Bind mount Python directory to some local folder
- Select Python interpreter in VS Code from that folder
- If needed, add directories for installed packages in a similar way (but I didn't manage to reach this stage yet)
I tried to implement everything using Django sample project from Docker docs, so my files looks like following
docker-compose.yml
version: '3'
services:
db:
image: postgres
web:
build: .
command: python3 manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
- ./.vscode/python:/usr/local/lib/python3.7 # The problem is here
ports:
- "8000:8000"
depends_on:
- db
Dockerfile
FROM python:3
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
RUN pip install -r requirements.txt
ADD . /code/
requirements.txt
Django
psycopg2
Django project works when the line - ./.vscode/python:/usr/local/lib/python3.7 is commented.
But when I am trying to bind mount Python folder the same way as /code folder mounted, I not only don't have content of this folder accessible locally, but Django project stops working.
Is it possible to mount Python executable in this way? Or maybe there is a better way to use arbitrary Python linters while using VS Code and Docker? It would be great to avoid:
- creating locally the same environment as in Docker container
- installing extensions that don't allow to use arbitrary linters