Like you who love programming!
Learn SpringBoot actual combat course https://edu.csdn.net/course/detail/31433
Learn SpringCloud introductory course https://edu.csdn.net/course/detail/31451
Overview
The previous article introduced how Docker deploys SpringBoot projects. It is troublesome to manually package, upload, create images, and run containers every time. IDEA provides a powerful Docker plugin to help us quickly complete project deployment.
Configure Docker remote connection
Modify docker service configuration
vi /usr/lib/systemd/system/docker.service
Modify the ExecStart item to
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
Restart docker
systemctl daemon-reload
service docker restart
Use Docker plugin
IDEA usually comes with its own Docker plugin. If you don’t have one, you can search in Plugins and
click Docker in the Settings menu. Click the plus sign above to add a Docker connection. Add the IP address of the Docker server in the URL. The default port is 2375. "Connection successfully" appears below to connect.
In the Services window, you can open the Docker connection, and you can see the images and containers in Docker.
Click Images to pull the image.
Enter the required image in the Repository and you can download it. If it is too slow, you can configure the Alibaba Cloud image
. In addition, you can also create containers in the form, start and stop running, delete images and containers, etc., which can replace docker commands.
Deploy the SpringBoot project
Simple project code
@RestController
public class HelloController
{
@GetMapping("/hello")
public String hello(){
return "Hello Docker!!";
}
}
In the root directory of the project, the new Dockerfile file
oa-0.0.1-SNAPSHOT.jar is the package file name of the project, which can be found in the target directory. The
exposed port is 8088, and then execute the jar file
FROM java:8
VOLUME /tmp
COPY /target/oa-0.0.1-SNAPSHOT.jar app.jar
RUN bash -c "touch /app.jar"
EXPOSE 8088
ENTRYPOINT ["java", "-jar", "app.jar"]
Click Edit Configuration, click the plus sign and select the Dockerfile
configured under Docker. Choose your own new file. The image tag and container name can be filled in. Bind port is to add the binding port,
so that the port of the docker internal container can be mapped to the Docker host. After the host port is
completed, package the project and
run Docker. After the deployment is successful, the image and running container of the project will appear in the Images and Container.
You can access the project deployed in Docker.
If you modify the project, you can repackage it and click Redeploy. You can quickly complete Docker deployment.
End
Okay, that's it for this article, bye
If you need to learn other Java knowledge, poke here ultra-detailed knowledge of Java Summary