The project package to generate executablejar
We went to the root directory of the project, run mvn clean package
the project package, after running will target
generate a directory xxx.jar
of executable jar
files.
Production Docker
mirror
First, we will prepare a xxx.jar
copy to our Ubuntu18 on the machine, do not copy the method described, we recount it. I am here I will generate docker-demo-0.0.1.jar
copied to the /var/docker/
folder. Here we do not necessarily use Linux
the machine, but here I used the demo, as far as possible in line with the production environment.
writeDockerfile
Use vi Dockerfile
of the file for editing.
FROM openjdk:8-jdk-alpine
VOLUME /tmp
ADD docker-demo-0.0.1.jar app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
The above explanation related commands:
- Docker get from the warehouse
openjdk
as a container of our project VOLUME
Points to a/tmp
directory, because the Spring Boot using the built-in Tomcat container, Tomcat is used by default/tmp
as the working directory. The effect is the host/var/lib/docker
creates a temporary file in the directory, and is connected to the container/tmp
.- The project
docker-demo-0.0.1.jar
asapp.jar
added to the container. ENTRYPOINT
Implementation of the projectapp.jar
. In order to shorten the Tomcat startup time, add a system property points/dev/urandom
as Entropy Source
Construction of Docker Mirror
We /var/docker/testdocker
directory, execute Docker
the command to build the image.
docker build -t docker-user-service:latest .
This command is to use Docker
the build
command to build the mirror, and the mirror has a name for docker-demo-user-service
it TAG
is latest
in the current folder.
We used docker images
to see all the images.
We found that there are our mirror list generated image docker-demo
.
Run-time image
Through the above steps we have completed the creation of the mirror, then we only need to use the docker run -p 8080:8080 -t jerome.xin/docker-demo
command to run our projects. Next we pass http://192.168.2.119:8080/
access to the project. Results are as follows:
We can see the normal return our expected results. Here to explain 192.168.2.119
this is the address of my virtual machines. If you do not want to see Spring Boot
the startup log we can use this command to docker run -d -p 8080:8080 -t jerome.xin/docker-demo
start the project.
Execution docker ps
to see the image that we have to run.
docker ps
If you need to stop the vessel, you can execute the following command.
docker stop 55e9e3a65e07
to sum up
Use Docker
can be used in the implementation of jar
the production and operation of the mirror, it can be summarized in two steps. The first step is ready to be executed by a jar
file, the second step to prepare Dockerfile
documents, and finally use Docker
the build
command you can put an executable jar
production of documents into images. Because our executable jar
file is used embedded Tomcat
container, so we are just from Docker
the central warehouse to pull a JDK
as a container to our image.
Spring Boot,Docker,Jar