In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to realize the dynamic management and monitoring functions of docker container based on springboot and docker-java". The explanation content in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian slowly and deeply to study and learn together "how to realize the dynamic management and monitoring functions of docker container based on springboot and docker-java"!
docker profile
Docker is an open-source application container engine, and compared with traditional virtual machine technology, docker container performance overhead is extremely low, so it is also popular with developers. With more and more docker-based developers, docker images are also richer, and all kinds of enterprise-level complete solutions in the future can be used directly by downloading images. Docker is becoming increasingly important.
purpose of this paper
This article introduces how to manage and monitor docker container through docker external interface through a project example.
Application scenarios:
Server resource pool is managed uniformly through docker, resources are allocated according to needs and containers are created to maximize resource utilization. At the same time, it ensures the isolation between various services (containers). It also supports online deployment of projects.
1. Create tomcat container of docker through interface and configure quota.
Upload the war package and deploy it to the container.
3. Dynamically monitor resource usage of all Docker containers.
The code is based on docker-java open source components and based on spring-boot to complete functional development. The interface is as follows:
basic environment
1、eclipse 2019-03;
2、docker for windows。For learning and simplicity purposes, the linux environment is not used, but the principles and basic commands are the same.
Related technologies and knowledge points:
maven, spring-boot;spring mvc;spring upload download, jquery ajax and upload.
realization principle
Docker provides rich interfaces (such as restfull api), through which docker can be managed. Docker-java open source components are encapsulated based on this interface to make development easier. Of course, there are other packaged components on the market, you can compare and learn by yourself. Thanks to the open source authors.
Pre-preparation of the realization process
1. Upgrade Windows
Since we are using windows environment, the author's own computer is pre-installed with win10 home edition, and docker for windows needs to run on a higher level operating system to use virtualization technology, so it needs to be upgraded to professional edition.
If you need to upgrade, the upgrade process is relatively simple, as follows (already professional version can be skipped):
Click Change Product Key, enter the Professional version of the key, and wait for the upgrade. The key is found on the Internet, anyway.
Install Docker for Windows
Go to the official website to download, all the way to the next step. After installation, it will start itself, and the docker logo will appear in the toolbar after startup.
After successful installation, you can type some commands to test whether it is successful. For example, check docker basic information.
3. Modify the docker mirror address.
Because the default mirror address is slow, a tomcat mirror is more than 500 m, the network is not good download will be slow, you can configure the mirror address to Netease mirror address, as follows:
4. Start remote management
Check the last item above, where tcp//xxx is the remote connection address.
After launching, type the address in the browser to see if it returns the result:
(Enter docker indo in cmd for this address) The returned content is in json format:
Code development for implementation process
1. Create a maven project.
Because of the simplicity of the procedure, this procedure is omitted. The code structure of the entire project is as follows:
2. Configure the maven dependency of docker-java and spring boot, and the final pom file content is as follows
By looking at the jar package, docker-java should be using netty dependencies at the bottom.
3. Add the spring configuration file application.properties
Configure the location of jsp and the administrative address of docker.
4. Introduction to main categories:
1. Spring boot starts the main class.
Of course, you can configure other containers or start them with maven's jetty plugin.
Can refer to another article: spring-boot principle (with the implementation of a spring-boot-starter example) with source code download
Notice where this class is placed, preferably in the root directory, so that all subdirectories under the root directory can be scanned by spring.
dockerclientoperaterserver (class that interacts with docker), as follows:
include that following method:
initclient: Initialize the link.
getdockerinfo: Get basic docker information;
stat: Real-time statistical information;
freshcontainers: Get basic information about all containers and put it into cache;
create and startrcontaineranddeploy app: Create and launch containers according to parameters passed by the interface, and deploy projects at the same time;
stopcontainer: stop container;
rmcontainer: Delete container;
closeclient: close the link;
pushapptocotainer: deploy war package to tomcat;
Because the code snippet is too long, here are a few main methods:
create container:
This method uses docker-java to create containers, allocate quotas, configure port mappings, etc.
pushapptocotainer: deploy project to tomcat
stat, monitoring method:
Monitoring this piece does not use docker-java methods, in fact, it is supported, but because the return results require a variety of processing, they use opportunistic methods. Use java to call cmd to execute (docker stats) to get monitoring results.
Docker-java code to obtain monitoring information is as follows:
Dockerclientcontroller (controller interacting with the interface).
Introduction to main methods:
addcontainer: add containers and upload war packages
This is the explanation of the main code.
Specific code details, please download the source code to start according to the process to view.
The main interface after implementation:
Since this is a sample project, the code doesn't use any vue and bootstrap frameworks. I wrote CSS and JS myself. The specific effects are as follows:
1. Monitoring Management Home Page
2. Add containers;
Thank you for reading, the above is "based on springboot and docker-java how to achieve dynamic management and monitoring of docker container" content, after learning this article, I believe that we have a deeper understanding of how to achieve dynamic management and monitoring of docker container based on springboot and docker-java, the specific use of the situation also needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.