What is Spring (Boot)?
The Spring framework is an open-source framework for building Java web-based applications. It has a lot of features that make it a popular choice for developers. On the other hand, Spring Boot is a project that is built on top of the Spring framework. It provides a simpler and faster way to set up, configure, and run both web-based and standalone applications.
In this article, we will discuss how to get started with Spring Boot with Docker and devcontainer.
Getting Started
We will use docker devcontainer to develop the Spring Boot application. Please make sure you have Docker and Visual Studio Code installed on your machine.
Step 1: Setup devcontainer
Create a new directory for your project and create a new file named dockerfile.devel
with the following content:
Suppose we are using PostgreSQL as the database. We need to create a new file named docker-compose.devel.yaml
with the following content:
We are using docker compose to manage the development environment. We have two services: java-devel
and java-postgres
. The java-devel
service is used to develop the Spring Boot application, while the java-postgres
service is used to run the PostgreSQL database.
Next, we need to create a new directory .devcontainer
and create a new file named devcontainer.json
with the following content:
Our directory structure should look like this:
In order to start the devcontainer environment, we can open the project directory in VSCode and press CTRL+SHIFT+P
and type Dev Containers: Reopen in Container
. This will start the devcontainer environment.