VSCode Remote Container: SpringBoot Demo

Ragunath Rajasekaran
4 min readJan 5, 2022

--

In this blog, we will demonstrate how a developer can leverage VSCode Remote Container to provide a sophisticated SpringBoot development environment.

Photo by Clark Tibbs on Unsplash

Please check out my previous blog to know why a developer needs VSCode Remote Container.

In this blog we can find out how to configure the VSCode remote container for Spring Boot application

In this blog, we can explore how to optimise the SpringBoot Development Environment with the help of Docker and VSCode Remote Container.

What we will cover in this tutorial?

As part of the demonstration, we will look into the following,

  • VSCode .devcontainer config
  • VSCode’s orchestration for building and starting docker image
  • Auto-SSH
  • Source code Auto-Mount
  • Run SpringBoot app Inside VSCode Remote Container
  • Debug SpringBoot Inside VSCode Remote Container

VSCode .devcontainer config

Just imagine that we have configured the Docker and VSCode infrastructure (inside .devcontainer folder) for a SpringBoot project and committed the configuration on source control.

Sample Docker Configuration can be seen below.

Sample devcontainer.json can be seen below.

You can find the step by step guide to configure these items for SpringBoot projects in this blog.

One of your teammates is opening the application folder in VSCode and it contains the necessary configurations (inside the .devcontainer folder). VSCode offers to Reopen in a container as shown in the below image.

VSCode Offers to Open Source Code Inside Docker Container

VSCode’s orchestration for building and starting docker image

When the developer clicks Reopen in Container, then VSCode do the following,

  1. Executes a set of commands in the background to build a docker image
  2. Starts the docker container

After the docker container is started, we can see the project source code in the left panel of VSCode. We can also see the list of commands executed in the VSCode terminal as indicated in the picture below.

VSCode Builds docker image and starts the container

Auto-SSH

When developers open the terminal in VSCode then they may notice they are in the docker container. VSCode auto ssh into the docker container.

For those who are new to the docker-ssh , please check the below link for more details.

When developers execute the pwd command in the VSCode Terminal to find out the current working directory, it is displayed as /workspace/em-api (see picture below).

VSCode Auto SSH into Docker Container

Source code Auto-Mount

Here VSCode auto-mounts your source in the container. So any changes to the source files will be local to the docker container and also to local development machine.

Run SpringBoot app Inside VSCode Remote Container

To run our demo SpringBoot app, the machine needs to be configured with the following,

  1. Java language setup
  2. Gradle setup
  3. Environment variables for Java and Gradle

As we already configured these tools with Dockerfile (inside of .devcontainer) properly, we can see that all these tools are available to us inside the docker container. Now the environment is ready to launch the Spring Boot app. Just run the gradle bootRun command (this command will be used to run the Spring Boot application using gradle) on the command line to run the application. View the application output as shown in the image below.

Executing SpringBoot App From Docker Container

Debug SpringBoot Inside VSCode Remote Container

VSCode should be installed with the Java Extension Pack to debug Java applications inside the VSCode. Look at the below screenshot where the execution is stoped on /heath endpoint from the HealthRestController while debugging the SpringBoot app.

SpringBoot App Debug Inside Docker Container

Now, One can imagine what kind of benefits can be achieved with VSCode Remote Container.

As a developer, once the basic infrastructure is configured then they don’t need to spend time on the environment setup. They can just open the project in VSCode from any machine (If Docker & the VSCode remote container installed) and Just Run.

In this blog we can find the step-by-step guide on setting up the VSCode remote container for the Spring Boot app.

Ragunath Rajasekaran has experience in developing full stack applications using SpringBoot, Node, React and GraphQl technologies. He is also the AWS & Azure cloud specialist who uses the infrastructure as code (IAC) via Terraform. He worked with Spark & Hive Big Data technologies. He debuted his career as an iOS developer.
Let’s connect to Ragunath Rajasekaran through LinkedIn, GitHub, Dev.to, Medium Email Subscription

--

--

Ragunath Rajasekaran

Sr. Tech Lead | Spring Boot | Big Data | AWS | Terraform | Spark | React | Docker