VSCode. How to set up a Docker development environment on a remote server via SSH
Connect via SSH to a remote machine via VSCode. For this we choose Command Palette
from the menu View
enter >
and choose a team Remote SSH: Connect to Host...
.
After that, you need to select a host or enter the command by which you connect in the terminal.
If the desired host does not exist, you must also specify the location of the SSH client configuration. Usually this ~/.ssh/config
After configuration, you can go to the machine through the IDE
Open repository via Docker container. For this:
– Go to the repository
– Create a folder .devcontainer
– Create files devcontainer.json
And Dockerfile.dev
.
devcontainer.json
stores metadata for setting up a development environment in the form of a dictionary. You can read more Here. The following parameters are required:
– name
– the name of the project, which will be displayed in the editor itself. In the current example, this i.lucky_dev_lightning
– context
– the context in which development will take place (in other words, the repository that will be the root). In the current example, it’s just ..
(we go one level above the folder .devcontainer
)
– dockerFile
– the name of the docker file that will be used to create the image → the container itself. In the current example, this Dockerfile.dev
.
– extensions
– a list of extensions that are necessary to work on the project. For more details about extensions, see Here. The extension names here are as follows:<EXTENSION_NAME>@<VERSION>
Here it is important to fix the version of each extension, because an unexpected situation may occur, as a result of which the work may be delayed (the built-in linter will suddenly start to give errors that were not there before, tests will not start from the editor, etc.). Usually for working with projects on Python
I am using the following set of extensions:
[
"ms-python.python@2022.18.2", // для работы на Python
"eamodio.gitlens@12.1.1", // надстройка для работы с git
"GrapeCity.gc-excelviewer@4.2.55", // редактор таблиц
"njpwerner.autodocstring@0.6.1", // автодобавление docsting
"KevinRose.vsc-python-indent@1.17.0", // автовыравнивание
"RobbOwen.synthwave-vscode@0.1.14", // просто цветовая схема (можно не брать)
"kaih2o.python-resource-monitor@0.1.9" // мониторинг использования RAM/CPU (можно не брать)
]
– runArgs
– list of parameters to be used for the command run
container. In the current example I am using:
[
"--name",
"i.lucky_dev_lightning"
]
– remoteUser
– exercise non-root
the same user that you use on the remote machine.