Step 1
Find a spring boot project can run here with a chapter-1-spring-boot-quickstart-1.0.jar
springboot project can run
(here I use the cloud service Ali lightweight application server)
to prepare a Dockerfile
file
FROM java:8-alpine
ADD chapter-1-spring-boot-quickstart-1.0.jar springboot.jar
EXPOSE 8090
ENTRYPOINT ["java","-jar","/springboot.jar"]
Description:
- FROM Specifies the source base image composed of a mirror, such as the project to rely jdk environment (8-alpine version of java representatives)
can be found on the official websitehttps://hub.docker.com
- ADD copied to the local file system file of the target vessel (
chapter-1-spring-boot-quickstart-1.0.jar
the representative file,springboot.jar
representative of a target file to be generated) - External port EXPOSE container map (of course, when the back of the container may be specified at runtime mirror)
- ENTRYPOINT container configuration command is executed after startup, the third parameter
springboot.jar
to the second parameter and the rear consistent ADD
Step 2
The two documents prepared by the above: chapter-1-spring-boot-quickstart-1.0.jar
, Dockerfile
uploaded to the linux server
Step 3
Input docker build -t springboot .
to build the image
Note: springboot
the future generation of image name, .
but also do not forget
[root@izwz91m0zmp2dlo94i0ptoz lee]# docker build -t springboot .
Sending build context to Docker daemon 14.33 MB
Step 1/4 : FROM java:8-alpine
---> 3fd9dd82815c
Step 2/4 : ADD chapter-1-spring-boot-quickstart-1.0.jar springboot.jar
---> 9c368d9d6266
Removing intermediate container b9221d4ec497
Step 3/4 : EXPOSE 8090
---> Running in f6aef702d0b4
---> dc580028919c
Removing intermediate container f6aef702d0b4
Step 4/4 : ENTRYPOINT java -jar /springboot.jar
---> Running in 80f0e8c17027
---> e33afac4394a
Removing intermediate container 80f0e8c17027
Successfully built e33afac4394a
You can see the success of the last generation of the mirror can also docker images
view to:
Step 4
Run-time image as container
Step 5
Browser access
47.107.226.177
This is an external address my Ali cloud server, which is the local address of the machine docker
This post is simple, this is the basis for the use of a combination of springboot and docker, please correct me if wrong, we learn together
If there are not very familiar with the command of the Docker, please refer to another article I Bowen: the basic use of Docker