springboot docker packaging image and dockerfile writing

springboot docker packaging image and dockerfile writing

First use the maven packaging command to package the project

//maven命令行打包并跳过测试包
mvn clean package -Dmaven.test.skip=true

Write dockerfile

Create Dockerfile
content

FROM openjdk:8-jdk
VOLUME /tmp
ADD target/zyyd-jstx-web-0.0.1-SNAPSHOT.jar app.jar
# EXPOSE 1130
# RUN sh -c 'touch /app.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]

## 1.FROM openjdk:8-jdk

It is to specify the base image, which must be the first command to find the jdk image from docker to specify the base image
2. VOLUME /tmp
maps the /tmp directory in the container to the host directory to view the mapped host directory docker inspect add8a3790

insert image description here
3. ADD target/zyyd-jstx-web-0.0.1-SNAPSHOT.jar app.jar
Put the generated jar package into the container
4. EXPOSE
specifies the port to interact with the outside world, format: EXPOSE […] Example: EXPOSE 8080 443 , EXPOSE 80 , EXPOSE 11431/tcp 12551/udp
5.RUN sh -c 'touch /app.jar'
Run the command touch /app.jar The touch command file has an update time, but there is no created file.
6. ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/app.jar"] The
command executed by java is followed by
parameters Parameter 1 - Djava.security.egd=file:/dev/./urandom execute random number strategy to avoid tomcat stuck when starting
parameter 2 -jar start command
parameter 3 start the current app.jar

docker packaging command

docker build -f Dockerfile -t jstx-web:v1.0 .
Parameter 1 -f specifies the dockerfile file
Parameter 2 -t specifies the container name Note that there is a . behind it.

Run the packaged docker image

1. View the docker image
docker images
2. Run the image
docker run -p 8080:8080 --name=deom001 jstx-web:v1.0
Parameter 1 Port external mapping
Parameter 2 Running container name
Parameter 3 Running image name

Guess you like

Origin blog.csdn.net/shixiaodongmain/article/details/124162572