Skip to content

Complete source code to Hot reload your Java Spring Boot and Micronaut applications inside docker with debugging support via IntelliJIdea

License

Notifications You must be signed in to change notification settings

one2nc/hot-reload-inside-docker-examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hot-Reload-Inside-Docker-Examples

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

Prerequisites

Samples of Hot Reload Inside Docker application with multiple integrated services

Running the application

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

Explanation

Key Concepts

  • Volume Mapping
  • Gradle / Maven Dependency Caching

Volume Mapping

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.

Gradle / Maven Dependency Caching

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).

Remote Debugging Using IntelliJIDEA

remote-debugging-intellij.mp4

About

Complete source code to Hot reload your Java Spring Boot and Micronaut applications inside docker with debugging support via IntelliJIdea

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •