用springboot直接build docker image

Spring boot

pom.xml

這邊接續上篇springboot 切換application.properties, 於是pom 檔中會需要辨別localprod
設定好之後可以在 中決定 name

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<build>
<resources>
<resource>
<directory>src/main/resources/config</directory>
<filtering>true</filtering>
<includes>
<include>application-${active.profile}.properties</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<name>df-eip</name>
</image>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>local</id>
<properties>
<active.profile>local</active.profile>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<active.profile>prod</active.profile>
</properties>
</profile>
</profiles>

build docker image

使用springboot 的指令即可建置出image

1
spring-boot:build-image -P local

首次建會載image 'docker.io/paketobuildpacks/builder:base 會花不少時間, 建完之後查看

1
docker image ls
  • output
    REPOSITORY TAG IMAGE ID CREATED SIZE
    df-eip-app latest 23d63a5da6d9 53 minutes ago 463MB

docker compose

1
2
3
4
5
6
7
8
9
10
11
12
13
version: '3'
services:
app:
image: df-eip:latest
ports:
- "80:80"
depends_on:
- redis
redis:
image: "redis:alpine"
ports:
- "6379:6379"

docker run

1
docker-compose up

Docker 啟動!


用springboot直接build docker image
https://shengshengyang.github.io/2023/12/19/springboot-build-docker-image/
作者
Dean Yang
發布於
2023年12月19日
許可協議