From 4fdf113bbd081083e86610405f58a119a2bdfed3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BA=AF=E6=B4=81=E7=9A=84=E5=BE=AE=E7=AC=91?= Date: Tue, 13 Mar 2018 18:25:58 +0800 Subject: [PATCH] m --- README.md | 2 + README_EN.md | 2 +- spring-boot-docker/pom.xml | 66 +++++++++++++++++++ spring-boot-docker/src/main/docker/Dockerfile | 4 ++ .../main/java/com/neo/DockerApplication.java | 12 ++++ .../com/neo/controller/DockerController.java | 13 ++++ .../src/main/resources/application.properties | 0 .../java/com/neo/DockerApplicationTests.java | 18 +++++ spring-boot-hello/pom.xml | 1 - 9 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 spring-boot-docker/pom.xml create mode 100644 spring-boot-docker/src/main/docker/Dockerfile create mode 100644 spring-boot-docker/src/main/java/com/neo/DockerApplication.java create mode 100644 spring-boot-docker/src/main/java/com/neo/controller/DockerController.java create mode 100644 spring-boot-docker/src/main/resources/application.properties create mode 100644 spring-boot-docker/src/test/java/com/neo/DockerApplicationTests.java diff --git a/README.md b/README.md index 8b307a9..3098fef 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,8 @@ Spring Boot使用的各种示例,以最简单、最实用为标准 - [spring-boot-hello](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-hello):Spring Boot 2.0 Hello World 示例 - [spring-boot-banner](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-banner):Spring Boot 定制 Banner 示例 +- [spring-boot-docker](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-banner):使用 Docker 部署 Spring Boot 示例 + **参考文章** diff --git a/README_EN.md b/README_EN.md index 0c5aa65..263cbbf 100644 --- a/README_EN.md +++ b/README_EN.md @@ -14,7 +14,7 @@ Spring Boot Examples, Use the simplest and most useful scene demo. - [spring-boot-hello](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-hello):Spring Boot 2.0 Hello World Demo - [spring-boot-banner](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-banner):Spring Boot Customized Banner - +- [spring-boot-docker](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-banner):Spring Boot with Docker --- diff --git a/spring-boot-docker/pom.xml b/spring-boot-docker/pom.xml new file mode 100644 index 0000000..17946da --- /dev/null +++ b/spring-boot-docker/pom.xml @@ -0,0 +1,66 @@ + + + 4.0.0 + + com.neo + spring-boot-docker + 1.0 + jar + + spring-boot-docker + Demo project for Spring Boot + + + org.springframework.boot + spring-boot-starter-parent + 2.0.0.RELEASE + + + + UTF-8 + 1.8 + springboot + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + com.spotify + docker-maven-plugin + 1.0.0 + + ${docker.image.prefix}/${project.artifactId} + src/main/docker + + + / + ${project.build.directory} + ${project.build.finalName}.jar + + + + + + + + + + diff --git a/spring-boot-docker/src/main/docker/Dockerfile b/spring-boot-docker/src/main/docker/Dockerfile new file mode 100644 index 0000000..be52a48 --- /dev/null +++ b/spring-boot-docker/src/main/docker/Dockerfile @@ -0,0 +1,4 @@ +FROM openjdk:8-jdk-alpine +VOLUME /tmp +ADD spring-boot-docker-1.0.jar app.jar +ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"] \ No newline at end of file diff --git a/spring-boot-docker/src/main/java/com/neo/DockerApplication.java b/spring-boot-docker/src/main/java/com/neo/DockerApplication.java new file mode 100644 index 0000000..d3a0276 --- /dev/null +++ b/spring-boot-docker/src/main/java/com/neo/DockerApplication.java @@ -0,0 +1,12 @@ +package com.neo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class DockerApplication { + + public static void main(String[] args) { + SpringApplication.run(DockerApplication.class, args); + } +} diff --git a/spring-boot-docker/src/main/java/com/neo/controller/DockerController.java b/spring-boot-docker/src/main/java/com/neo/controller/DockerController.java new file mode 100644 index 0000000..8b6ba67 --- /dev/null +++ b/spring-boot-docker/src/main/java/com/neo/controller/DockerController.java @@ -0,0 +1,13 @@ +package com.neo.controller; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class DockerController { + + @RequestMapping("/") + public String index() { + return "Hello Docker!"; + } +} \ No newline at end of file diff --git a/spring-boot-docker/src/main/resources/application.properties b/spring-boot-docker/src/main/resources/application.properties new file mode 100644 index 0000000..e69de29 diff --git a/spring-boot-docker/src/test/java/com/neo/DockerApplicationTests.java b/spring-boot-docker/src/test/java/com/neo/DockerApplicationTests.java new file mode 100644 index 0000000..b08b689 --- /dev/null +++ b/spring-boot-docker/src/test/java/com/neo/DockerApplicationTests.java @@ -0,0 +1,18 @@ +package com.neo; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class DockerApplicationTests { + + @Test + public void contextLoads() { + System.out.println("hello docker"); + } + +} diff --git a/spring-boot-hello/pom.xml b/spring-boot-hello/pom.xml index fa53732..eba4356 100644 --- a/spring-boot-hello/pom.xml +++ b/spring-boot-hello/pom.xml @@ -20,7 +20,6 @@ UTF-8 1.8 - springboot