Hot swap not working for Spring Boot project inside Docker container

124 views Asked by At

I'm working on an open-source project called DLCM (link). The backend is built with Spring Boot and is running inside a Docker container. My development environment is VS Code, and I'm sharing volumes between my host machine and the Docker container to reflect the code changes.

However, when I make changes to the code, I currently have to rebuild everything, which is time-consuming. To remedy this, I integrated the Spring Boot DevTools into my project:

 <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <scope>runtime</scope>
    <optional>true</optional>
 </dependency>

I run the project within the Docker container using:

mvn -f /app/DLCM-Solution/pom.xml spring-boot:run -Dspring-boot.run.arguments="--spring.config.location=/app/administration.properties" -Dlicense.skipCheckLicense

Unfortunately, even with DevTools integrated, hot reloading (hot swap) isn't functioning as expected. Here's the Docker Compose configuration for the backend:

dlcm-administration:
    image: development-dlcm-backend-image
    # image: maven:3.6-openjdk-11
    # image: $DOCKER_REGISTRY/dlcm-solution:$DLCM_SOLUTION_VERSION
    container_name: light-administration
    restart: always
    volumes:
      - ~/.m2:/root/.m2
      - /home/ricardo/inuits/fair-vault/poc/fairvault-common/DLCM-Backend:/app # Mount source code
      - /etc/timezone:/etc/timezone:ro
      - dlcm-light-administration-tmp-volume:/tmp
      - dlcm-light-home-volume:/home/dlcm/:rw
      - /home/ricardo/inuits/fair-vault/dlcm-demo-docker-compose/dlcm-light/administration.properties:/app/administration.properties
    command: mvn -f /app/DLCM-Solution/pom.xml spring-boot:run -Dspring-boot.run.arguments="--spring.config.location=/app/administration.properties" -Dlicense.skipCheckLicense
    # command: tail -f /dev/null
    ports:
      - '$IP_ADDRESS:$DLCM_ADMINISTRATION_PORT:$DLCM_ADMINISTRATION_INTERNAL_PORT'
    networks:
      - lightnet
      - infranet
    mem_limit: 8g

I expect the code to hot swap as I make changes in my local development environment and to automatically rebuild inside the container. I chose this Docker setup to utilize its networking features and to streamline the setup process for future developers.

Has anyone encountered and resolved a similar issue? Any pointers would be greatly appreciated.

0

There are 0 answers