I've created a spring starter project with gradle as dependency manager and also including spring-boot-dev-tools. My aim is to create a docker image so that there must be live reload whenever I change a java file inside docker container. This is working well with following configurations.
Dockerfile
FROM gradle:5.6.2-jdk8
WORKDIR /app
COPY . /app
RUN gradle build
EXPOSE 8080
CMD ["sh", "start.sh"]
start.sh
#!/bin/bash
gradle --version
gradle build --continuous &
gradle bootRun
This is working
One of my controller file is as follows.
@RestController
public class MainController {
@GetMapping("/")
String test() {
return "Test Success";
}
}
Getting "Test Success" in browser when navigating to localhost:8080
. When the file /app/.../MainController.java
inside docker container is changed to say, return "Updated";
, the change is affected automatically.
This is the issue
Even if there is RUN gradle build
inside Dockerfile, docker run
command with this image seems to be downloading the gradle dependencies again because of the command gradle build --continuous
or gradle bootRun
.
I want the docker run
command fast, like it's downloaded all the dependencies already. Please suggest a workaround. Live reload is needed.