Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hot reload java program running in docker

I developed a java program which is supposed to run in docker. However, I encountered a lot of pains when debugging my java program running in docker.

I searched on Internet, some tutorials proposed tools like spring-dev-tools (as my java program is a spring-boot-based program).

https://www.youtube.com/watch?v=sz5Zv5QQ5ek

Based on thoses tutorials, debugging is ok, such as setting breakpoint and variable watching, however, when I update my code (for instance, some classes), thoses changes cannot be reflected immediately in the program running in docker, the programm behaves as old code.

Can anybody give some hints ?

like image 897
Shu Avatar asked Mar 24 '19 09:03

Shu


1 Answers

I have managed to make this work by doing the following:

  1. Mount the source code into the container at runtime
  2. Connect using a remote debugger

Here is my dockerfile:

FROM gradle:5.4-jdk12
WORKDIR /app
EXPOSE 8080 5005

and here is my docker-compose.yml:

version: '3'
services:
  app:
    build:
      context: .
    ports:
      - 5005:5005
      - 8080:8080
    volumes:
      - .:/app
    command: ["gradle", "bootRun"]

when I run this using docker-compose up and then connect a remote debugger, the hot reloading works.

I am connecting from Intellij so I have to rebuild the project for the hot reloading to work.

like image 75
the_witch_king_of_angmar Avatar answered Oct 16 '22 23:10

the_witch_king_of_angmar