Skip to content

Commit 9034517

Browse files
author
yadong.zhang
committed
Springboot整合Docker
1 parent b119f33 commit 9034517

File tree

6 files changed

+133
-1
lines changed

6 files changed

+133
-1
lines changed

pom.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222
<module>springboot-exception</module>
2323
<module>springboot-mail</module>
2424
<module>springboot-ssl</module>
25-
</modules>
25+
<module>springboot-multi-datasource</module>
26+
<module>springboot-restdocs</module>
27+
<module>springboot-docker</module>
28+
</modules>
2629

2730
<parent>
2831
<groupId>org.springframework.boot</groupId>

springboot-docker/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Springboot 结合Docker
2+
3+
1. pom

springboot-docker/pom.xml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<parent>
4+
<artifactId>springboot</artifactId>
5+
<groupId>com.zyd</groupId>
6+
<version>0.0.1-SNAPSHOT</version>
7+
</parent>
8+
<modelVersion>4.0.0</modelVersion>
9+
10+
<artifactId>springboot-docker</artifactId>
11+
<packaging>jar</packaging>
12+
13+
<name>springboot-docker</name>
14+
<url>http://maven.apache.org</url>
15+
16+
<properties>
17+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18+
<!-- docker镜像的前缀:springboot -->
19+
<docker.image.prefix>springboot</docker.image.prefix>
20+
</properties>
21+
22+
<dependencies>
23+
<dependency>
24+
<groupId>junit</groupId>
25+
<artifactId>junit</artifactId>
26+
<version>3.8.1</version>
27+
<scope>test</scope>
28+
</dependency>
29+
</dependencies>
30+
31+
<build>
32+
<plugins>
33+
<plugin>
34+
<groupId>org.springframework.boot</groupId>
35+
<artifactId>spring-boot-maven-plugin</artifactId>
36+
</plugin>
37+
<!-- maven插件:docker-maven-plugin -->
38+
<plugin>
39+
<groupId>com.spotify</groupId>
40+
<artifactId>docker-maven-plugin</artifactId>
41+
<version>0.4.11</version>
42+
<configuration>
43+
<imageName>${docker.image.prefix}/${project.artifactId}</imageName>
44+
<dockerDirectory>src/main/docker</dockerDirectory>
45+
<resources>
46+
<resource>
47+
<targetPath>/</targetPath>
48+
<directory>${project.build.directory}</directory>
49+
<include>${project.build.finalName}.jar</include>
50+
</resource>
51+
</resources>
52+
</configuration>
53+
</plugin>
54+
</plugins>
55+
<finalName>springboot-docker</finalName>
56+
</build>
57+
</project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# FROM指定使用哪个镜像作为基准
2+
FROM openjdk:8-jdk-alpine
3+
# VOLUME为挂载路径 -v
4+
VOLUME /tmp
5+
# ADD为复制文件到镜像中
6+
ADD springboot-docker.jar app.jar
7+
# RUN为初始化时运行的命令 touch更新app.jar
8+
RUN sh -c 'touch /app.jar'
9+
# ENV为设置环境变量
10+
ENV JAVA_OPTS=""
11+
# ENTRYPOINT为启动时运行的命令
12+
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.zyd;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.web.bind.annotation.GetMapping;
6+
import org.springframework.web.bind.annotation.RestController;
7+
8+
@SpringBootApplication
9+
@RestController
10+
public class Applaction {
11+
@GetMapping("/")
12+
public String index() {
13+
return "测试Springboot集合docker";
14+
}
15+
16+
public static void main(String[] args) throws Exception {
17+
SpringApplication.run(Applaction.class, args);
18+
}
19+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.zyd;
2+
3+
import junit.framework.Test;
4+
import junit.framework.TestCase;
5+
import junit.framework.TestSuite;
6+
7+
/**
8+
* Unit test for simple App.
9+
*/
10+
public class AppTest
11+
extends TestCase
12+
{
13+
/**
14+
* Create the test case
15+
*
16+
* @param testName name of the test case
17+
*/
18+
public AppTest( String testName )
19+
{
20+
super( testName );
21+
}
22+
23+
/**
24+
* @return the suite of tests being tested
25+
*/
26+
public static Test suite()
27+
{
28+
return new TestSuite( AppTest.class );
29+
}
30+
31+
/**
32+
* Rigourous Test :-)
33+
*/
34+
public void testApp()
35+
{
36+
assertTrue( true );
37+
}
38+
}

0 commit comments

Comments
 (0)