The article turns from http://xiaoqiangge.com/aritcle/1500011474745.html
Now Docker is becoming more and more popular, it seems that whatever everything wants to put in the Docker, like Kafka in the Docker,mysql in the Docker,nginx in Docker, this article records the Springboot in Docker.
The content of the article requires you to have a certain understanding of Docker container technology, such as Docker pull, Docker Registry, Docker build, Docker run.
Suppose there was a scenario where I developed a springboot program locally and then submitted the code to git and docker the Springboot program into an image, You can then run this Springboot program on any machine with a Docker engine.
There are 2 implementations I've found, scenario A is the spring Boot with Docker from the official spring, and Scenario B is writing dockerfile to build Docker image, which is described in the following two ways.
Programme A
Spring officially provides the spring Boot with Docker way to make Docker image, as follows is its dockerfile,
From Frolvlad/alpine-oraclejdk8:slim
volume/tmp
ADD gs-spring-boot-docker-0.1.0.jar app.jar
RUN sh-c ' Touch/app.jar '
ENV java_opts= ' "
entrypoint [" sh ","-C "," JAVA $JAVA _opts-djava.security.egd=file:/dev/./ Urandom-jar/app.jar "]
From the dockerfile you can see that it is in the production of image is the first generation of Gs-spring-boot-docker-0.1.0.jar, and then add to the image by adding instructions, and then make a mirror, this practice is provided by the official, detailed reference to the above documents.
Programme b
Write your own dockerfile, including git on-pull substitution code, MAVEN packaging, startup programs, etc.
From CentOS
RUN yum-y update \
&& yum-y install git maven \
&& git http://xxx.git.com/xxx.gi T
RUN cd/xxx \
&& mvn clean package-dmaven.test.skip=true
entrypoint Java-jar/xxx.jar
Dockerfile is simple, and then using the Docker build, the command is mirrored.
To sum up, the results of these two methods are the same as the successful build image, but there are still some differences,
1. Programme a requires some Docker-related content to be configured in the program, and some jars are introduced, and there is code intrusion compared to scenario B.
2. Because of the use of the Add directive, there is always a need to maintain the presence of gs-spring-boot-docker-0.1.0.jar in the implementation of programme A's dockerfile, which is totally superfluous compared to programme B.
3. Assuming that our program is not a Java program, not a springboot, then scheme A will not be implemented, and program B can still continue to implement, but the process of packaging, start-up has changed.
Based on the above analysis I personally strongly recommend the use of program B.