VSCode container development environment construction (Remote-Containers)

Time:2022-11-24

foreword

I believe that programmers are already proficient at opening the IDE and typing codes on their computers. Installing java sdk and nodejs on the computer, these basic operations are also proficient enough to burst, but have you ever imagined migrating the development environment? into the container? Or code the development environment? You only need to install the IDE on your computer, connect it to the container, and you can develop and compile immediately. Does it sound a little exciting?

Recently, Microsoft released a set ofVSCodeplug-inRemote-Development. It allows developers toVSCodeDirectly access the remote directory for development work. In this way, our code and development environment can be separated from the terminal computer, which can avoid pollution to the local environment, and can freely set up multiple different development environments at the remote end to switch at any time. Combined with container technology, different development environments can be effectively integrated Carry out segmentation, and use containers as units to copy and migrate, and even package and distribute the same environmental requirements within the group. Newly recruited students do not need to build an environment, and can directly enter the development by connecting to the container. Let me lead you to build such a remote development environment from shallow to deep.

Pit warning

The so-called pit warning means that I will explain all the big and small pits I have walked through here at the beginning of the article, so that everyone can have a psychological expectation first… After all, in this world, apart from pits, there are only pits. Fucked (cover face).

  1. Remote-ContainersMany of the current functions of this set of plug-ins are based onlocal computerInstalleddockercontainer environment, although it supports connecting to remotedockerContainer, but after connecting to the remote end, there will be a lot of additional settings that need to be done…
  2. If you still need to compile the docker image function in your development environment (for example, if you want to compileQuarkusframednativemirror image. Don’t ask, I’m still in the pit and can’t get out…), there will be more messy and exotic beast-level errors. Of course, if only bymavenorgradlecompile ajarBagwarIt can be done easily with the package.

prepare the environment

A total of the following tools are required:

  1. VSCodebody
  2. Remote-Developementplug-in
  3. Docker CLI(Because the plug-in needs to use the native docker command)

Notice: Here I will separate two scenarios to illustrate:

  • [local]: Represents that the docker environment is directly installed on the local computer.
  • [remote]: Indicates that the docker environment is installed on the remote server.

1. Install VSCode

own motherdownload linkGo ~ Skip!

2. Install the plugin

according toCtrl+Shift+XOpen the plug-in interface, searchRemote DevelopmentJust install it.

VSCode container development environment construction (Remote-Containers)

3. Install docker

[local]If you want to install directly to your local computer and use the local docker environment, then installdocker desktopAfter installation, there will be a docker environment locally.

[remote]If you don’t want to install it locally and want to link to the docker on the remote server, you can install docker-cli. (Of course, there are the most pits…)

  1. downloaddocker.exe, put inPATHpath, so that the command line can be used directlydockerJust order.
  2. existcmdorpower shellfight insidedocker infoCommand, see something come out on it.

4. [remote]Enable the docker remote call api function[[1]](#reference article)

Run the following command to createoverride.conffile, then rebootdockerJust the process.

# create folder
$ sudo mkdir /etc/systemd/system/docker.service.d/

# create conf file
$ sudo vi /etc/systemd/system/docker.service.d/override.conf

# Add the following content to override.conf
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2375 --containerd=/run/containerd/containerd.sock

Notice:tcp://0.0.0.0:2375The port number can be modified according to your needs.

5. [remote]set VSCode[[2]](#reference article)

Yes, if you connect to the remote docker, you need to set the following things, yeah~

Open it in vscodesettings

VSCode container development environment construction (Remote-Containers)

searchdocker host, fill in the remotedockerthe address of:

VSCode container development environment construction (Remote-Containers)

have a test

After all settings are complete, click on theRemote Explorer, if you can see the docker container information, spicy is success.

VSCode container development environment construction (Remote-Containers)

at last

Let us learn together, progress together, and be bald together~

Welcome to pay attention to my personal public number! Private message me on the official account and I will reply in seconds~

VSCode container development environment construction (Remote-Containers)

reference article

[1] Docker official tutorial: Enable the remote api for dockerd

[2] Microsoft official tutorial: Developing inside a container on a remote Docker host