Deploying a SpringBoot App with an application.properties using a docker-composer.yml file and limiting resources
We saw how to deploy a Spring Boot application with its application.properties plus a .p12 key using an SSL certificate to secure Apache Tomcat or Netty in here https://springboot-vuejs-reactjs.blogspot.com/2019/12/springboot-with-applicationproperties.html
now let's do the same thing but using a docker-composer.yml with volumes instead of using images
so that this is going to give us the advantage about updating the .jar application and restarting the container without rebuilding the whole image.
let's create a folder in which you are going to have your .jar app, the application.properties and .p12 key to secure with SSL your SpringBoot app and any other files you need to run your application,
as in the previous post if you need a mini SpringBoot app to test it, grab this https://github.com/juandavidmarin368/SpringBoot-Docker
I've got a domain name with the one I do the tests with SSL and it is http://sslbackendtest.xyz/
I've created a file inside that folder called service_one.yml and this is what let run the java app on a docker container
.
now to run it and to see in action on the console in order to check if everything worked OK, run this
now let's do the same thing but using a docker-composer.yml with volumes instead of using images
so that this is going to give us the advantage about updating the .jar application and restarting the container without rebuilding the whole image.
let's create a folder in which you are going to have your .jar app, the application.properties and .p12 key to secure with SSL your SpringBoot app and any other files you need to run your application,
as in the previous post if you need a mini SpringBoot app to test it, grab this https://github.com/juandavidmarin368/SpringBoot-Docker
I've got a domain name with the one I do the tests with SSL and it is http://sslbackendtest.xyz/
I've created a file inside that folder called service_one.yml and this is what let run the java app on a docker container
this is an application.properties to have SSL on SpringBoot
docker-compose -f service_one.yml up
now to run int in Detached mode or in the background run this:
docker-compose -f service_one.yml up -d
to see the containers running docker container ls
if you've got a new .jar version of the same app, just replace in the host folder the jar by the new one
and run docker container restart service_one
service_one was the name given to the container if you need to stop it run
docker container stop service_one
LIMITING RESOURCES TO THE DOCKER CONTAINER
what about if you need to give it limited resources to the container because of many reasons,
for instance what about if your application starts taking the whole ram memory and the whole processors you've got?, it would get the whole OS host down, and to avoid that if we've identified which services are taking a lot of resources by limiting their resources.
I am using Docker-compose 3 for the purpose of the example and it is as easy as adding this block of
instructions
in which I am saying the application is going to use 40% of the whole CPUs and 400Mb ram memory
now let's test it in Linux Centos 7 as the host OS
1: let's run the docker-compose /usr/local/bin/docker-compose --compatibility -f service_one.yml up
2: let's open 2 more terminals on the host OS
3: in one of the terminals let's go to the container shell with this command
docker exec -it --user root service_one bash we are now logged in as root into the container service_one
once we are there let's run apt-get update && apt-get install stress and after it has ended up let's run
I am using Docker-compose 3 for the purpose of the example and it is as easy as adding this block of
instructions
now let's test it in Linux Centos 7 as the host OS
1: let's run the docker-compose /usr/local/bin/docker-compose --compatibility -f service_one.yml up
2: let's open 2 more terminals on the host OS
3: in one of the terminals let's go to the container shell with this command
docker exec -it --user root service_one bash we are now logged in as root into the container service_one
once we are there let's run apt-get update && apt-get install stress and after it has ended up let's run
stress --cpu 8 --io 2 --vm 1 --vm-bytes 300mb
with the last instruction, we are using the binary stress with the one we are simulating the resources of the CPU and ram memory in this case we are saying to it, take the whole permitted CPU and around 300mb
4: let's open another terminal in the host OS and let's run yum install htop after that run htop
with the last instruction, we are using the binary stress with the one we are simulating the resources of the CPU and ram memory in this case we are saying to it, take the whole permitted CPU and around 300mb
4: let's open another terminal in the host OS and let's run yum install htop after that run htop
We can see now how the whole CPU is being used around 40% plus taking approximately the ram memory we allow to use it
Comments
Post a Comment