Monitor Spring Boot App running in Docker via JMX - java

I am using docker swarm & Traefic to manage and deploy my containers. Unfortunately, I didn't set it up and not sure details, all I do is just deploy my app there and everything taken care of.
I am running Spring Boot Apps, each app could have multiple instances.
Docker file is pretty simple,
basically
ENTRYPOINT java -jar /app.jar
And we use Traefic to manage it as well.
I am trying to connect jconsole to different apps but not sure how to do it for remote app that runs in docker swarm remotely. Locally no issues.
I read on an internet about setting JMX setting when starting java app but all information about connecting to app running in docker locally or with static IP. I imagine I do not have static IP to add to my configuration, it always assigned dynamicly.
Any advise or where to start look would be gladly appreciated

To map multiple containers, you can use the container hostname.
When you run a container like "docker run -ti ... --hostname test1 ..." or run a service "docker service create ... name= test1...".
So, you have to hitting via hostname.
Regards.

Related

Access DB data on a running spring boot in docker container like Ruby console script/console

I am wondering if is there a way to connect and interact with a running spring-boot application inside a docker container.
For example: In rails running application inside a docker container can be connected via the following commands, (let's say the name of the container is rails_app_1)
docket container exec -it rails_app_1 bash
script/console
It will load the rails app in the proper context and I can interact with DB and also call/execute application code and even find the DB objects like
Employee.find(1234) // This finds the employee with Id 1234
Is there a way to do a similar thing in Java for a spring-boot application running in the docker container and I can load some console in proper spring context in order to run some scripts?
Thanks

How to set/create docker images for application that uses kafka and cassandra

I have a java spring boot application.
This application make use of cassandra as data storage and kafka for messaging.
I am using the image for cassandra and zookeeper and kafka locally to run them.
I also created DockerFile for my web app, and build the file to create a image.
My application when run, connect to cassandra database.
When I run the application(intelij), it works fine by connecting to cassandra(running as docker) but when I run docker image locally for the same application, the app image container is not able to connect to cassandra running locally and hence fails.
What do I need to do such that I can run the docker container for the app and also connecting to cassandra.
I don't know the exact specifics of your connection details (host:port) that you are using in your application but the most common mistake in this situation is using localhost.
localhost in the docker container is not the same as localhost when you are starting your application outside the docker container. Therefore when starting the application inside the docker container you have to specify a different hostname for your cassandra deployment.
By default docker will use the container id as the container hostname so you would have to replace localhost with your cassandra container id or alternatively start the cassandra container using --hostname in order to define a hostname that you wish to use.
In the end a more elegant solution would be to use a docker compose file where the hostname of each service is the service name. This is very helpful for starting together multiple services that "talk" to each other.
You can find everything I explained to you regarding the hostnames of containers here.
Also here you can find a nice intro into docker compose.
version: '3'
services:
web:
build: .
ports:
- "5000:5000"
redis:
image: "redis:alpine"
In this example the hostnames for each service are web and redis. You can apply this to your compose file and use the corresponding hostnames for cassandra and kafka.

How to host spring-boot micro-service dockerized(docker compose) application on Heroku

I have developed small spring-boot microservice application and dockerized the same. I have multiple spring-boot services and angular which are dockerized using docker-compose file. My app runs fine in my local. I just wanted to host my app on Heroku for free. please help me how to host my app and how to configure multiple ports with application. how to deploy using docker-compose.
First of all, you can not run your docker-compose in heroku.
Docker is not required
If you will choose heroku, docker is not required. Just ensure that your spring boot apis and angular app are standard. If you fulfill that, just create many applications as git repositories you have (I guess you have it like this).
Smart heroku engine will detect the technology of your git repository and will provide you an standard dyno for your app. After that heroku will run standard commands of open source languages.
For example, heroku will run npm install and npm run start in your angular/nodejs app. If you don't put the start script in your package.json, an error will be trowed. The same will happen with your spring boot rest api.
If you have any error with your current spring boot apis, try to compare it with my templates https://github.com/jrichardsz/spring-boot-templates/tree/master/000-hello-world.
I want docker
Anyway, if you want to use docker in heroku, just put the classic Dockerfile inside of any git repository and push them to heroku. Smart engine will detect it and deploy it.
1.You don't need docker as answered already. See this link for deployment to Heroku
You could also deploy using Travis CI for continuous integration via github.

Use Docker to invoke .NET Core from Java

I have made a small .NET Core REST API which I would like to be able to easily put on a Linux server running a Java app on Tomcat. Can one use Docker to ease the deployment of the .NET tool, and if so, how is it done? I was told by someone that Docker would (more or less) allow me to bundle the API as a single app/file without having to bother too much about deployment policies at the place I am working (which by default only allows for Java apps to Bd deployed).
You can use a docker image like e.g. microsoft/dotnet to run your app in a docker container. Please read the documentation on the linked page on how to run your app inside the container.
If you then map an exposed port (443, 80, 8080... depends on you app) using the -p option on container startup you can then access the REST endpoints from any software you like because it is basically behaving like an other REST server running on that host. Since you want to run tomcat in parallel you should avoid to map the port from the container to 8080 on you host, thought! Other than that this setup is totally independent from the application server running on the host itself.

How to get the Docker Container Id from inside a running docker image via Java API?

Not finding anything on the University of Google so checking here. I have an enterprise application running on an application server inside a docker image. During the running time, the enterprise application needs to use a Java API call to obtain the Docker Container Id that it's running in. How is this done?
In general, when docker runs a container it should set the hostname with the id of the container, so just reading the environment variable HOSTNAME (or the file /etc/hostname) should do it.
If this does not work, provide more information about your setup.

Categories