VScode in Dev Container does not override local Workspace Settings with the Remote Settings
I am developping with vscode devcontainers, and I absolutely love it :)
However, I have an issue with the automatic linting, on save.
I have the black linter in local, that works correctly, with the following configuration in the workspace settings (.vscode/settings.json
):
{
"python.formatting.provider": "black",
"python.formatting.blackPath": "~/venv/.style-check/bin/black",
"editor.formatOnSave": true,
}
In local, each time that I save my file, it runs the black formatter so that my code gets the correct layout and formatting. However in the devcontainer, it does not work properly.
I am running a custom image, based on the microsoft's python official image that already includes all the usual linting libraries (black, flake8, bandit...).
It also already provides the custom remote settings.json
, with the path where the binaries are installed :
{
"python.defaultInterpreterPath": "/usr/local/bin/python",
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
"python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
...
}
Black is correctly installed, I can manually run the formatter with black my_file.py
, and everything works as expected.
VScode also correctly launches the formatter on save : after a ctrl+S on myfile.py
, I could have a look at the logs by going to the output
view of the integrated terminal, and choosing Python
in drop-down menu.
These logs clearly show that vscode executed the black
linter as expected, but using the local path ("~/venv/.style-check/bin/black"
) which obviously did not work.
However, the official documentation insists on the fact that the remote settings should override the local workspace settings.
I also checked if the remote settings were correctly identified, by adding in my in .devcontainer/devcontainer.json
, the example from the documentation linked just above. It immediately reflected in the remote container settings.json (/home/vscode/.vscode-server/data/Machine/settings.json
).
To summarize, it seems the container itself is perfectly set-up, but the vscode window isn't.
What is going on here ? Why are the remote settings not taken into account ?
I am running out of ideas at this point :/
(PS : I asked ChatGPT, which confusely said something about sync settings, but I didn't really get it. I just thought I would let you know this piece of information.)
You can try to use a new workspace for remote connection.
As the official document said, the purpose of coverage is to maintain the consistency of user experience. It is best to avoid writing path-related settings in the workspace you are currently using.