Skip to content

Commit d2f85b1

Browse files
committed
pom配置文件构建项目镜像
1 parent 4474cd0 commit d2f85b1

File tree

3 files changed

+59
-6
lines changed

3 files changed

+59
-6
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,10 @@
1111
### 启动服务
1212
```bash
1313
nohup java -jar springboot-mybatis-web-0.0.1-SNAPSHOT.jar >> smw.log 2>&1 &
14-
```
14+
```
15+
16+
### 服务器构建项目镜像
17+
```bash
18+
cd /root/answer/docker/springboot-mybatis-web
19+
mvn package docker:build -Dmaven.test.skip=true -X
20+
```

pom.xml

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
44
<modelVersion>4.0.0</modelVersion>
55

66
<groupId>com.answer</groupId>
77
<artifactId>springboot-mybatis-web</artifactId>
8-
<version>0.0.1-SNAPSHOT</version>
8+
<version>1.0.0</version>
99
<packaging>jar</packaging>
1010

1111
<name>springboot-mybatis-web</name>
@@ -73,8 +73,55 @@
7373
<artifactId>spring-boot-maven-plugin</artifactId>
7474
<version>1.4.2.RELEASE</version>
7575
</plugin>
76+
77+
78+
79+
<!-- Docker Maven插件 -->
80+
<plugin>
81+
<groupId>com.spotify</groupId>
82+
<artifactId>docker-maven-plugin</artifactId>
83+
<!-- Docker镜像相关的配置信息 -->
84+
<configuration>
85+
<!-- 镜像名, 这里用工程名 -->
86+
<imageName>${project.artifactId}</imageName>
87+
<!-- 镜像版本号, 可设置多个, 如果不是设为latest, 则会生成两个镜像, 即设置的版本号和latest -->
88+
<imageTags>
89+
<imageTag>latest</imageTag>
90+
<!--<imageTag>${project.version}</imageTag>-->
91+
</imageTags>
92+
<!-- 镜像的FROM, 使用java官方镜像 | 构建镜像时需要的基础镜像, 类似于DockerFile的From -->
93+
<baseImage>java:8</baseImage>
94+
<!--该镜像的容器启动后, 直接运行spring boot工程 | 容器启动时执行的命令 -->
95+
<entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]</entryPoint>
96+
<!--<volumes>
97+
<volume></volume>
98+
</volumes>-->
99+
<!-- 设置环境变量 | 类似于DockerDile的ENV -->
100+
<env>
101+
<MYSQL_IP>119.23.106.146</MYSQL_IP>
102+
<MYSQL_PORT>3306</MYSQL_PORT>
103+
<MYSQL_DB>answer</MYSQL_DB>
104+
<MYSQL_UNAME>root</MYSQL_UNAME>
105+
<MYSQL_PASSWD>123456</MYSQL_PASSWD>
106+
</env>
107+
<!-- 设定容器向外部暴露的端口 -->
108+
<exposes>
109+
<expose>8088</expose>
110+
</exposes>
111+
<!-- 这里是复制 jar 包到 docker 容器指定目录配置, 相当于DockerFile的ADD -->
112+
<resources>
113+
<resource>
114+
<targetPath>/</targetPath>
115+
<directory>${project.build.directory}</directory>
116+
<include>${project.build.finalName}.jar</include>
117+
</resource>
118+
</resources>
119+
</configuration>
120+
</plugin>
76121
</plugins>
77122

123+
124+
78125
<!-- 解决打包时访问不了JSP问题 -->
79126
<resources>
80127
<!-- 打包时将jsp文件拷贝到META-INF目录下-->

src/main/resources/application.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ server.servlet.context-path=/smw
55
spring.application.name=smw
66

77
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
8-
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/answer?useUnicode=true&amp;characterEncoding=utf-8&amp;allowMultiQueries=true
9-
spring.datasource.username=answer
10-
spring.datasource.password=7654321
8+
spring.datasource.url=jdbc:mysql://${MYSQL_IP:127.0.0.1}:${MYSQL_PORT:3306}/${MYSQL_DB:answer}?useUnicode=true&amp;characterEncoding=utf-8&amp;allowMultiQueries=true
9+
spring.datasource.username=${MYSQL_UNAME:answer}
10+
spring.datasource.password=${MYSQL_PASSWD:7654321}
1111

1212
spring.mvc.view.prefix=/pages/
1313
spring.mvc.view.suffix=.jsp

0 commit comments

Comments
 (0)