Application example of deploying spring boot using docker
The development of docker technology provides a more convenient environment for the landing of micro services. It is actually very simple to deploy spring boot with docker. Let's learn this article.
First, build a simple spring boot project, then add docker support to the project, and finally deploy the project.
A simple spring boot project
In POM XML, using spring boot 2.0 related dependencies
Add Web and test dependencies
Create a dockercontroller, in which there is an index () method. When accessing, it returns: Hello docker!
Startup class
Start the project after adding. After successful startup, the browser asks: http://localhost:8080/ , the page returns: Hello docker, This indicates that the spring boot project is configured normally.
Add docker support to spring boot project
In POM Add docker image name in XML properties
Add docker build plug-ins to plugins:
Create a dockerfile in the directory Src / main / docker. The dockerfile file is used to explain how to build an image.
The dockerfile file is very simple. Build the basic JDK environment and add the spring boot jar to the image. Briefly explain:
This completes adding docker dependencies to the spring boot project.
Build packaging environment
We need a docker environment to package the spring boot project. It is troublesome to build a docker environment in windows, so I take CentOS 7 as an example.
Install docker environment
install
After installation, use the following command to start the docker service and set it to startup:
Using docker China accelerator
Restart docker
Enter docker version to return the version information, and the installation is normal.
Install JDK
Configure the environment variable and open VIM / etc / profile to add the following contents
After the modification is completed, make it effective
Enter Java - version to return the version information, and the installation is normal.
Installing maven
Download: http://mirrors.shu.edu.cn/apache/maven/maven-3/3.5.2/binaries/apache-maven-3.5.2-bin.tar.gz
Example code: https://github.com/ityouknow/spring-boot-examples