Sara Selim
Sara Selim

Reputation: 467

How to automate spring boot docker commands

How to build one Gradle task that clean and build springBoot jar then build and run the command of docker-compose up in order to automate/combine the steps and commands in one call for having up and running docker image of spring boot application

Upvotes: 1

Views: 162

Answers (1)

GreenSaguaro
GreenSaguaro

Reputation: 3387

  1. Add this plugin to your Gradle project:

https://github.com/avast/gradle-docker-compose-plugin

  1. Set up the Docker Compose plugin:
dockerCompose {
    forceRecreate = true
}
  1. Make the composeUp task depend on clean and bootJar:
tasks.composeUp.dependsOn('clean', 'bootJar')
  1. Create your Dockerfile that will build your image using the JAR output from the bootJar task

  2. Create your Docker Compose file, and include an entry that will build your image:

services:
  spring-boot-app:
    build: .
    ports:
      - "8080:8080"
  1. ./gradlew composeUp

Upvotes: 1

Related Questions