4

In development I have a Java backend API which I'm running with Tomcat. I'm wanting to wrap the backend in a docker container and deploy to an AWS EC2 instance, and be able to scale up/down.

Does every docker container need to have a separate Tomcat server running? I don't know any way around it, but I guess it just seems like a lot of overhead (1GB-2GB memory, 500MB disc space) per container.

  • 1
    If you're using AWS, then it's worth exploring ECS. – Dan Wilson Nov 6 '19 at 12:43
  • 1
    Does every docker container need to have a separate Tomcat server running? yes. it just seems like a lot of overhead (1GB-2GB memory, 500MB disc space) per container then review how is your docker image built. Or do review why your app needs so many resources. I run similar images with much fewer resources. – Laiv Nov 6 '19 at 13:44
  • 1
    Tomcat by itself does not need that much resources. Tomcat 8 by itself only needs about 50MB of RAM, and requires about 20-30MB of disk space (and the disk space will be shared by different docker containers automatically if they share the same base image). The 1-2GB RAM requirement is probably from your application. – sleske Nov 6 '19 at 14:10
  • @Laiv Good to know. I was quoting minimum requirements from a search I did on Tomcat, but it seems the source may be old/incorrect – nanotek Nov 6 '19 at 14:12
  • 1
    You have first to measure your requirements. You have two: minimum and the desirable. The minimum is the setup required to keep running the app in idle or with almost no load. The desirable is the max needed to hold the max load (+15-20%). Then when you need more throughput, you deploy one more replica instead of increasing the resources of the running container. If your minimum is too high, it's likely the service, is not that "micro" – Laiv Nov 6 '19 at 14:54
4

In the Microservices architecture, usually, you want the flexibility to deploy the services independently and this requirement leads you to have one container per service with all the dependency and environment necessary to run it.

The default Java ecosystem is heavy to create cloud-native applications, but this is changing with projects like Quarkus and GraaVM where you can build cloud-native applications with high performance and low memory consumption.

|improve this answer|||||
3

Consider using embedded Tomcat inside your application instead of deploying your app in a Tomcat instance. I prefer this approach in general but it's definitely much more aligned with micro-service architectures and containers.

|improve this answer|||||
2

You don't need docker in this instance.

Tomcat is already a container running system which can run multiple seperate websites and apis

|improve this answer|||||
  • 1
    Can you scale each site in a Tomcat instance independently? – Dan Wilson Nov 6 '19 at 13:07
  • 1
    no but you cant do that with docker on a single ec2 either – Ewan Nov 6 '19 at 13:31
  • 3
    Yes, this. Both Tomcat and Docker (intend to) solve the same problem: Provide a consistent environment for an application/service. They just do so at different levels (basically, Tomcat provides the Servlet API, while Docker provides the Linux API). – sleske Nov 6 '19 at 14:06
  • Of, course you might want to use Docker for the advantages it provides... – sleske Nov 6 '19 at 14:10
  • 1
    This article: the decline of Java application servers when using docker containers explains the advantages Docker offers over just using an application server (like Tomcat). This may not apply in all situations, but there are things that Docker can do while Tomcat alone cannot. – sleske Nov 8 '19 at 10:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.