Docker-deploy a Java project

You may not be outstanding, but you must be different

Docker deploy Java project

Server operation based on Centos7.6

Docker deployment jar package project

Deploy by packaging into a mirror

1. Create a folder

Pass in the jar package type project

2. Create a Dockerfile

Insert picture description here

3. Edit the Dockerfile

FROM java:8
VOLUME /temp
ADD schoolinfo.jar schoolinfo.jar
RUN bash -c 'touch /schoolinfo.jar'
ENTRYPOINT ["java","","-jar","-Xmx500m","-Xms500m","/schoolinfo.jar"]

4. Start building the image

docker build -t test/schoolinfo .

5. View the docker image

docker images

6. Use the docker image to run the container

docker run -d -p 8081:8081 --name schoolinfo test/schoolinfo
[[email protected] ~]# cd /root/jarfile
[[email protected] jarfile]# docker build -t test/schoolinfo .
Sending build context to Docker daemon   72.3MB
Step 1/5 : FROM java:8
 ---> d23bdf5b1b1b
Step 2/5 : VOLUME /temp
 ---> Running in 32012e9ed635
Removing intermediate container 32012e9ed635
 ---> fe3f4e1fe03a
Step 3/5 : ADD schoolinfo.jar schoolinfo.jar
 ---> 648fbcf5c901
Step 4/5 : RUN bash -c 'touch /schoolinfo.jar'
 ---> Running in 7d0e8f2c9b06
Removing intermediate container 7d0e8f2c9b06
 ---> 3c35f77022d8
Step 5/5 : ENTRYPOINT ["java","","-jar","-Xmx500m","-Xms500m","/schoolinfo.jar"]
 ---> Running in 8b4436b7bbe5
Removing intermediate container 8b4436b7bbe5
 ---> 203ba233c236
Successfully built 203ba233c236
Successfully tagged test/schoolinfo:latest
[[email protected] jarfile]# docker run -d -p 8081:8081 --name schoolinfo test/schoolinfo
[[email protected] jarfile]# 

Use java -jar to run project deployment

1. Upload the jar package project that needs to be deployed to the centos server

2. Upload the jar package to home. Here I upload schoolinfo.jar to home.

3.kdvolder/jdk8 is the mirror image of my jdk8


docker pull kdvolder/jdk8

4. Run with docker

[[email protected] ~]# docker run -d --restart=always  -p 8081:8081 -v /home/schoolinfo.jar:/usr/schoolinfo.jar  --name schoolinfo kdvolder/jdk8  java -jar /usr/schoolinfo.jar


There may be two reasons for the inaccessibility of the project after successful startup

1. The mysql or redis or rabbitmq in the jar package project cannot be accessed if localhost is used. It is recommended to use the public network ip

2. The firewall of the server may have been turned on, or the port may not be open