how to create spring boot app and run as docker container
how to create spring boot app and run as docker container
------------------------------------------------------------
server:
port: 8080
spring:
application:
name:
management:
endpoints:
web:
exposure:
include: "*"
health:
readinessstate:
enabled: true
livenessstate:
enabled: true
endpoint:
health:
probes:
enabled: true
@RestController
public class HelloController {
@Autowired
private InstanceInformationService instanceInformationService;
@GetMapping(path="hello-world")
public String hello(){
return "hello empapp
v2 :"+instanceInformationService.retrieveInstanceInfo();
}
}
@Service
public class InstanceInformationService {
FROM openjdk:21
MAINTAINER email="[email protected]"
EXPOSE 8080
ADD target/empapp.jar empapp.jar
ENTRYPOINT ["java","-jar","empapp.jar"]
docker image ls
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<name>rgupta00/${project.artifactId}:v1</name>
</image>
</configuration>
</plugin>
2. Run the maven command from the location where pom.xml is visible
mvn spring-boot:build-image
https://cloud.google.com/java/getting-started/jib
https://github.com/GoogleContainerTools/jib
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>3.4.1</version>
<configuration>
<from>
<image>openjdk:21</image>
</from>
<to>
<image>rgupta00/${project.artifactId}:v2</image>
</to>
</configuration>
</plugin>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>3.3.2</version>
<configuration>
<from>
<image>eclipse-temurin:21-jre</image>
</from>
<to>
<image>rgupta00/${project.artifactId}:v1</image>
</to>
</configuration>
</plugin>
2. Run the maven command from the location where pom.xml is visible
mvn compile jib:dockerBuild