Spring Boot Hello and docker

Source: Internet
Author: User

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:


<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&gt                ; <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>


 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);}    }


 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; }}


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.