Member-only story
Avoiding Visual Studio Code extension reinstalls on running Docker containers
How to save your state when Visual Studio Code isn’t responsible for running your development containers
Last week, I learned How To Attach Visual Studio Code To A Running Docker Container, but I didn’t have time to work through Avoiding VS Code extension reinstalls. Having lost random bits of time each day since to the reinstalls, I’ve just taken advantage of a quick break to take a look and I quickly realized that the instructions are only helpful if Visual Studio Code is responsible for composing and running the Docker containers, not if the containers are managed elsewhere — but not to worry! I’ve figured out how to do it so that you don’t have to ;)
The solution is actually very simple: create two folders that will be volume mounted to ~/.vscode-server and ~/.vscode-server-insiders (ie. if you’re connecting to your Docker container as root, then /root/.vscode-server and /root/.vscode-server-insiders).
As an example, I created the two folders inside dkr-vscode inside my home folder and mounted them as follows (see my previous article for a detailed explanation):
> docker run — rm — name mypython -it — entrypoint bash -v $(pwd):/root/myreponame -v /Users/myusername/dkr-vscode/.vscode-server:/root/.vscode-server -v /Users/myusername/dkr-vscode/.vscode-server-insiders:/root/.vscode-server-insiders python
While it seems as if Visual Studio Code will always reinstall itself anyway, that’s the quick and painless part, and your extensions will not be removed unless you delete them from your local machine. Done!