Spring Boot Admin inside Docker
Spring Boot Admin is great tool to manage and monitor your Spring Boot Applications. As the famous idiom says, a picture is worth a thousand words.
It offers really cool features and it is very easy to install, but… it gets bit more complicated when you have all your applications in Docker and want to run Spring Boot Admin in Docker as well.
If you use Spring Cloud supported service discovery solution like Netflix Eureka, Zookeeper or Consul you can probably run Spring Boot Admin within this service discovery and you are good to go. Find more about it in documentation.
In this post I will describe what you need to do if you are not using any of these service discovery tools and want to run Spring Boot Admin as Docker container along with you other Spring Boot applications.
Add Spring Boot Admin client dependency to your application. With Maven:
<dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-client</artifactId> <version>1.4.1</version>
In your Spring Boot application
application.propertiesfile, add URL pointing to Spring Boot Admin server.
- Create Docker network which enable Spring Boot Admin and other application to communicate
```bash $ docker network create admin-network ``` <p> Main obstacle to run Spring Boot Admin along with other application in Docker is that applications needs to communicate bidirectional. It is not possible to use <a href="https://docs.docker.com/engine/userguide/networking/default_network/dockerlinks/">„link” functionality</a> from Docker to create bidirectional link. Instead you should use new <a href="https://docs.docker.com/engine/userguide/networking/">Docker „networking” functionality</a>. It has been introduced in version 1.10 of Docker. If you are using earlier version of Docker I highly recommend to upgrade, but you can also try to use on of the solutions described on StackOverflow <a href="http://stackoverflow.com/questions/25324860/how-to-create-a-bidirectional-link-between-containers">here</a>. </div> </li>
Start Spring Boot Admin as Docker container
bash $ docker run -d -p 8080:8080 --net=admin-network --name admin aetas/spring-boot-admin-docker:1.4.1
Name of the container is used in the Docker network as a host name so Spring Boot Admin server will be visible under http://admin:8080 inside „admin-network” Docker network. This is why we’ve set „spring.boot.admin.url” to this URL in the step 2.
Image „aetas/spring-boot-admin-docker:1.4.1” is very basic Spring Boot Admin 1.4.1 dockerized. You can find it’s source on GitHub. In case you need to add some more specific options to your Spring Boot Admin server, you can fork the project, change it and run „gradle dockerBuild” to create your personalised Spring Boot Admin Docker image.
Start your dockerized application inside the same Docker network as Spring Boot Admin server Generally speaking you need to add one parameter („–net=admin-network„) to the „docker run” command which starts your application in Docker so it looks like this:
```bash $ docker run [... other options ...] --net=admin-network [your_app_image_name] ```
Your application should be already registered or should register in Spring Boot Admin shortly. Check Spring Boot Admin in browser by going to http://localhost:8080 (or http://192.168.99.100:8080 in case you’re still using Docker Machine on MacOS or Windows).
See more about Spring Boot Admin in documentation.