The main is to try the spring boot run in the Docker feel, small test sledgehammer:)
This is the original text, refer to: https://spring.io/guides/gs/spring-boot-docker/
1. Environment
Win10, Eclipse, MVN, CentOS 7.3 (VM), Docker 1.12
That is, the development environment under WIN10, Docker environment in the CentOS VM
2. Project diagram
Two code files: Application.java, Hellocontroller.java
A dockerfile to build the jar into a mirror
A pom.xml, this does not explain
3. Source Files:
Pom.xml
<project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" > <modelversion>4.0.0 </modelVersion> <groupId>SpringbootDocker</groupId> <artifactid>ex.springbootdocker</ artifactid> <packaging>jar</packaging> <version>0.0.1</version> <parent> <groupId>org.springframework.boot</groupId> <artifactid>spring-boot-starter-parent</ artifactid> <version>1.5.6.RELEASE</version> </parent> <properties> <jav a.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactid>spring-boot-starter-web</artifacti d> </dependency> </dependencies> <build> <plugins> <plugin> ; <groupid>org.springframeWork.boot</groupid> <artifactId>spring-boot-maven-plugin</artifactId> < Configuration> <fork>true</fork> </configuration> </plugin> <plugin> &L T;groupid>com.spotify</groupid> <artifactId>dockerfile-maven-plugin</artifactId> <version>1.3.4</version> <configuration> <repository>$ {docker.image.prefix}/${project.artifactid}</repository> </configuration> </plugi N> </plugins> </build></project>
Application.java
Package Ex.springbootdocker; Import org.springframework.boot.SpringApplication; Import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication Public class Application { publicstaticvoid main (string[] args) { Springapplication.run (Application. class , args);} }
Hellocontroller.java
PackageEx.springbootdocker;Importorg.springframework.web.bind.annotation.PathVariable;Importorg.springframework.web.bind.annotation.RequestMapping;ImportOrg.springframework.web.bind.annotation.RequestMethod;ImportOrg.springframework.web.bind.annotation.RestController; @RestController Public classHellocontroller {@RequestMapping (value= "/hello/{name}", method=requestmethod.get) PublicString SayHello (@PathVariable ("name") (String name) {return"Hello," +name; }}
Dockerfile
From openjdk:8-jdk-/tmpadd ex.springbootdocker-0.0.1. jar app.jarenv java_opts= "" -jar/app.jar
4. Description
1). My eclipse does not automatically generate jars, only mvn the package
2). Copy the generated jar and Dockerfile to the CentOS VM, e.g./opt/docker
3). Create image
4). Run
One more Firefox diagram:
Spring Boot Hello and docker