Full automation: First build the docker image warehouse, and then configure the warehouse address in the project's maven configuration. Configure the Dockerfile file in the project, so that it can be packaged directly in the idea and automatically uploaded to the image warehouse, and then just start the image on the server.
Semi-automation: There are two options for semi-automation. One is to place the Dockerfile file inside the project, and the other is to place it outside the project.
Put it in the project: configure maven plug-in support in springboot pom.
Generally speaking, semi-automation is used more than full automation. This article uses the second method of semi-automation. Generally speaking, there are several steps:1. Build the SpringBoot project Write a controller Conduct local testing 2. Package the applicationClick package to package the project Packaging successful cmd runs java -jar and it can run successfully You can download a Docker plug-in 3. Write dockerfileCreate the Dockerfile file in the target. At this time, the Dockerfile file is highlighted Dockerfile configuration content (there will be prompts when writing Dockerfile in Idea)
#发布到网上时只会把jar包和Dockerfile发布上去 COPY *.jar /app.jar #地址映射 CMD ["--server.port=8080"] #对外暴露端口 EXPOSE 8080 #执行命令 ENTRYPOINT ["java","-jar","/app.jar"]
(Note: Docker Desktop is installed on my computer)
After the image is built successfully, run the container (the first is the server port 8080, the second 8080 is the docker container port) You can see whether the container is running and the logs Information Access successful 5. Release and runYou can upload the image to dockerhub, After using Docker in the future, all you need to deliver to others is an image!
The above is the detailed content of How to package SpringBoot project into Docker image. For more information, please follow other related articles on the PHP Chinese website!