My employer is interested in using Docker to containerize their web applications. We use AWS EC2 to host our applications, which runs Tomcat serving multiple WARs. I'm new to Docker and need to figure out how best to handle this.
As I understand, it's not proper to have a single Docker container running multiple web applications. So for each application I should build a container from a Tomcat base image, and just copy the WAR to the tomcat/webapps directory, like so in the Dockerfile:
FROM tomcat:9.0.44-jdk11-openjdk
COPY ./target/my-app-1.00-SNAPSHOT.war $CATALINA_HOME/webapps/my-app.war
Simple enough, works fine. But the Tomcat image is 440MB. So if we have Tomcat currently running 5 WAR files that are each 50 MB or so, and each one gets its own container running Tomcat, we're looking at a tenfold increase in size for each application. That seems...really inefficient. Is this really the cost of using Docker containers? How can I minimize this?
I'm also not sure how to handle ports. Right now port 8080 is mapped to subdomain.mydomain.com. But each container will obviously be running on a different port. So let's say I launch a container for my-app-1 on port 8080, and a container for my-app-2 on 8081. How can I allow users to simply navigate to subdomain.mydomain.com/my-app-1, and subdomain.mydomain.com/my-app-2?