JAVA-12420 Renamed docker to docker-modules
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
### Relevant Articles:
|
||||
|
||||
- [Creating Docker Images with Spring Boot](https://www.baeldung.com/spring-boot-docker-images)
|
||||
- [Starting Spring Boot Application in Docker With Profile](https://www.baeldung.com/spring-boot-docker-start-with-profile)
|
||||
@@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>docker-spring-boot</artifactId>
|
||||
<name>docker-spring-boot</name>
|
||||
<description>Demo project showing Spring Boot and Docker</description>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung.docker</groupId>
|
||||
<artifactId>docker-modules</artifactId>
|
||||
<version>0.0.1</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.junit.vintage</groupId>
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<layers>
|
||||
<enabled>true</enabled>
|
||||
<configuration>${project.basedir}/src/layers.xml</configuration>
|
||||
</layers>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<java.version>11</java.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,27 @@
|
||||
<layers xmlns="http://www.springframework.org/schema/boot/layers"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/boot/layers
|
||||
https://www.springframework.org/schema/boot/layers/layers-2.3.xsd">
|
||||
<application>
|
||||
<into layer="spring-boot-loader">
|
||||
<include>org/springframework/boot/loader/**</include>
|
||||
</into>
|
||||
<into layer="application" />
|
||||
</application>
|
||||
<dependencies>
|
||||
<into layer="snapshot-dependencies">
|
||||
<include>*:*:*SNAPSHOT</include>
|
||||
</into>
|
||||
<into layer="internal-dependencies">
|
||||
<include>com.baeldung.docker:*:*</include>
|
||||
</into>
|
||||
<into layer="dependencies" />
|
||||
</dependencies>
|
||||
<layerOrder>
|
||||
<layer>dependencies</layer>
|
||||
<layer>spring-boot-loader</layer>
|
||||
<layer>internal-dependencies</layer>
|
||||
<layer>snapshot-dependencies</layer>
|
||||
<layer>application</layer>
|
||||
</layerOrder>
|
||||
</layers>
|
||||
@@ -0,0 +1,16 @@
|
||||
# To build, run the following command from the top level project directory:
|
||||
#
|
||||
# docker build -f src/main/docker/Dockerfile .
|
||||
|
||||
FROM adoptopenjdk:11-jre-hotspot as builder
|
||||
ARG JAR_FILE=target/*.jar
|
||||
COPY ${JAR_FILE} application.jar
|
||||
RUN java -Djarmode=layertools -jar application.jar extract
|
||||
|
||||
FROM adoptopenjdk:11-jre-hotspot
|
||||
COPY --from=builder dependencies/ ./
|
||||
COPY --from=builder spring-boot-loader/ ./
|
||||
COPY --from=builder internal-dependencies/ ./
|
||||
COPY --from=builder snapshot-dependencies/ ./
|
||||
COPY --from=builder application/ ./
|
||||
ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"]
|
||||
@@ -0,0 +1,11 @@
|
||||
# To build and run docker-with-spring-profile:
|
||||
#
|
||||
# docker build -f src/main/docker/springprofile/Dockerfile --tag=docker-with-spring-profile:latest .
|
||||
# docker run docker-with-spring-profile:latest
|
||||
#
|
||||
# To run with profiles:
|
||||
# docker run -e "SPRING_PROFILES_ACTIVE=test1,test2,test3" docker-with-spring-profile:latest
|
||||
|
||||
FROM openjdk:11
|
||||
COPY target/*.jar app.jar
|
||||
ENTRYPOINT ["java", "-jar", "/app.jar"]
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
version: "3.5"
|
||||
services:
|
||||
docker-with-spring-profile:
|
||||
image: docker-with-spring-profile:latest
|
||||
environment:
|
||||
- "SPRING_PROFILES_ACTIVE=prod"
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
version: "3.5"
|
||||
services:
|
||||
docker-with-spring-profile:
|
||||
image: docker-with-spring-profile:latest
|
||||
environment:
|
||||
- "SPRING_PROFILES_ACTIVE=test"
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.baeldung.docker.spring;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class DemoApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(DemoApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package com.baeldung.docker.spring;
|
||||
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class HelloController {
|
||||
|
||||
@GetMapping("/hello")
|
||||
public ResponseEntity<String> hello()
|
||||
{
|
||||
return ResponseEntity.ok("hello2 ");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user