Use this repo to set up a fast local development environment in docker with a debugger. Using this repo, you can set up a SpringBoot or Micronaut application with the following features:
- application built inside docker
- code changes auto-compiled and updated without having to restart the app or container
- remote debugging using IntelliJIdea
- integration test execution using TestContainers in docker
- Make sure that you have Docker and Docker-Compose installed
- Windows or macOS: Install Docker Desktop
- Linux: Install Docker and then Docker Compose
Spring-Boot / Postgres
- Sample Java application with SpringBoot Framework and a Postgres database.
Micronaut / Postgres
- Sample Java application with Micronaut Framework and a Postgres database.
The root directory of each application, i.e SpringBoot and Micronaut contains a docker-compose.yml
file which describes the
configuration of service components. All the samples can be run in a local environment by going into the
root directory of the application and executing the following command:
docker compose up
Check the README.md
of the respective SpringBoot and Micronaut applications to get more details on the structure and what is the expected
output. To stop and remove all containers of the sample application run:
docker compose down
- Volume Mapping
- Gradle / Maven Dependency Caching
The essential component is mounting current directory from local machine to app
(WORKDIR)
directory
inside the Docker container. SpringBoot / Micronaut application by default comes with Maven / Gradle
Wrappers, this would allow us to run the application within the Docker container.
Mounting the current directory into the Docker container helps to have source code and the build tool within Docker container, but the source code within Docker is dependent on many external libraries(dependencies) that are not present in the current directory.
There are two ways to solve this issue:
- Mounting
.m2
/.gradle
from Docker Host to Docker container. - Caching all the dependencies while building the Docker image
Mounting root-level directories is not an option to choose. But there are some other issues with
Gradle
caching, if you are mounting .gradle
and running the application with Gradle build tool within
Docker container, then docker acquires the lock for Gradle cache, which means we
can't run any application with Gradle build in the local machine until the Docker container is stopped.
Caching all the dependencies while building a Docker image is a good option during the development phase. Since we are downloading all the dependencies image size would be larger(depends on the dependencies).