Skip to content

Commit 308db42

Browse files
Merge pull request eugenp#10031 from carloscaverobarca/BAEL-4574-Creating-Docker-Images-for-Spring-Boot-Microservices
BAEL-4574 - Creating-Docker-Images-for-Spring-Boot-Microservices
2 parents 86f154d + 0d65502 commit 308db42

File tree

8 files changed

+108
-14
lines changed

8 files changed

+108
-14
lines changed

docker/docker-internal-dto/pom.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>com.baeldung.docker</groupId>
8+
<artifactId>docker</artifactId>
9+
<version>0.0.1</version>
10+
</parent>
11+
12+
<artifactId>docker-internal-dto</artifactId>
13+
<name>docker-internal-dto</name>
14+
15+
</project>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.baeldung.docker.dto;
2+
3+
public class VariableDto {
4+
5+
private final String value;
6+
7+
public VariableDto(String value) {
8+
this.value = value;
9+
}
10+
11+
public String getValue() {
12+
return value;
13+
}
14+
}

docker/docker-spring-boot/pom.xml

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
45
<modelVersion>4.0.0</modelVersion>
56
<parent>
6-
<groupId>org.springframework.boot</groupId>
7-
<artifactId>spring-boot-starter-parent</artifactId>
8-
<version>2.3.1.RELEASE</version>
9-
<relativePath/> <!-- lookup parent from repository -->
7+
<groupId>com.baeldung.docker</groupId>
8+
<artifactId>docker</artifactId>
9+
<version>0.0.1</version>
1010
</parent>
11-
<groupId>com.baeldung.docker</groupId>
12-
<artifactId>spring-boot-docker</artifactId>
13-
<version>0.0.1-SNAPSHOT</version>
14-
<name>spring-boot-docker</name>
11+
12+
<artifactId>docker-spring-boot</artifactId>
13+
14+
<name>docker-spring-boot</name>
1515
<description>Demo project showing Spring Boot and Docker</description>
1616

1717
<properties>
18-
<java.version>8</java.version>
18+
<java.version>11</java.version>
1919
</properties>
2020

2121
<dependencies>
@@ -24,6 +24,12 @@
2424
<artifactId>spring-boot-starter-web</artifactId>
2525
</dependency>
2626

27+
<dependency>
28+
<groupId>com.baeldung.docker</groupId>
29+
<artifactId>docker-internal-dto</artifactId>
30+
<version>0.0.1</version>
31+
</dependency>
32+
2733
<dependency>
2834
<groupId>org.springframework.boot</groupId>
2935
<artifactId>spring-boot-starter-test</artifactId>
@@ -45,6 +51,7 @@
4551
<configuration>
4652
<layers>
4753
<enabled>true</enabled>
54+
<configuration>${project.basedir}/src/layers.xml</configuration>
4855
</layers>
4956
</configuration>
5057
</plugin>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<layers xmlns="http://www.springframework.org/schema/boot/layers"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://www.springframework.org/schema/boot/layers
4+
https://www.springframework.org/schema/boot/layers/layers-2.3.xsd">
5+
<application>
6+
<into layer="spring-boot-loader">
7+
<include>org/springframework/boot/loader/**</include>
8+
</into>
9+
<into layer="application" />
10+
</application>
11+
<dependencies>
12+
<into layer="snapshot-dependencies">
13+
<include>*:*:*SNAPSHOT</include>
14+
</into>
15+
<into layer="internal-dependencies">
16+
<include>com.baeldung.docker:*:*</include>
17+
</into>
18+
<into layer="dependencies" />
19+
</dependencies>
20+
<layerOrder>
21+
<layer>dependencies</layer>
22+
<layer>spring-boot-loader</layer>
23+
<layer>internal-dependencies</layer>
24+
<layer>snapshot-dependencies</layer>
25+
<layer>application</layer>
26+
</layerOrder>
27+
</layers>

docker/docker-spring-boot/src/main/docker/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ RUN java -Djarmode=layertools -jar application.jar extract
99

1010
FROM adoptopenjdk:11-jre-hotspot
1111
COPY --from=builder dependencies/ ./
12-
COPY --from=builder snapshot-dependencies/ ./
1312
COPY --from=builder spring-boot-loader/ ./
13+
COPY --from=builder internal-dependencies/ ./
14+
COPY --from=builder snapshot-dependencies/ ./
1415
COPY --from=builder application/ ./
1516
ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"]

docker/docker-spring-boot/src/main/java/com/baeldung/docker/DemoApplication.java renamed to docker/docker-spring-boot/src/main/java/com/baeldung/docker/spring/DemoApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.baeldung.docker;
1+
package com.baeldung.docker.spring;
22

33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;

docker/docker-spring-boot/src/main/java/com/baeldung/docker/HelloController.java renamed to docker/docker-spring-boot/src/main/java/com/baeldung/docker/spring/HelloController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.baeldung.docker;
1+
package com.baeldung.docker.spring;
22

33
import org.springframework.http.ResponseEntity;
44
import org.springframework.web.bind.annotation.GetMapping;

docker/pom.xml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>org.springframework.boot</groupId>
9+
<artifactId>spring-boot-starter-parent</artifactId>
10+
<version>2.3.1.RELEASE</version>
11+
<relativePath /> <!-- lookup parent from repository -->
12+
</parent>
13+
14+
<groupId>com.baeldung.docker</groupId>
15+
<artifactId>docker</artifactId>
16+
<version>0.0.1</version>
17+
<name>docker</name>
18+
<description>Demo project showing Spring Boot and Docker</description>
19+
<packaging>pom</packaging>
20+
21+
<properties>
22+
<java.version>11</java.version>
23+
</properties>
24+
25+
<modules>
26+
<module>docker-internal-dto</module>
27+
<module>docker-spring-boot</module>
28+
</modules>
29+
30+
</project>

0 commit comments

Comments
 (0)