Spring boot and docker deployment details
This article introduces the deployment of spring boot and docker. I hope it will be helpful to you
Enable docker remote access
First, you need to enable the docker remote access function so that remote operations can be performed.
CentOS 6
Modify the / etc / default / docker file to take effect after restarting (service docker restart).
CentOS 7
Open / usr / lib / SYSTEMd / system / docker Service file, modify the line execstart.
Effective after restart
Is the test effective
New Maven project
pom. The XML configuration is as follows:
Imagename: Specifies the name of the image
Dockerdirectory: Specifies the location of the dockerfile
Dockerhost: Specifies the docker remote API address
Resources: refers to the files that need to be put together with dockerfile and used when building the image. Generally, the application jar package needs to be included
Create a Java class
Create dockerfile
Create a file named dockerfile in Src / main / docker directory. The configuration is as follows:
From Java: refers to the java image officially provided on the docker hub. With this basic image, the dockerfile can directly obtain its status through the from instruction - that is, Java has been installed in the container, and then run the spring boot application through a custom command.
Volume / tmp: create the / tmp directory and persist it to the docker data folder, because the embedded Tomcat container used by spring boot uses / tmp as the working directory by default.
ADD docker-springboot-0.0. 1-SNAPSHOT. jar app. Jar: copy the application jar package to / app.jar jar
Entrypoint: indicates the command executed by default after the container is run
The complete directory structure is as follows:
Run the following command to create a docker image: package docker: build
Docker start image
Check whether the project is uploaded successfully
Start mirroring
Access via browser
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.