I’ve have a Red Hat Enterprise Docker container where I install Tomcat and am running a custom Tomcat application. I wish to deploy it to Elastic Beanstalk. The application works as expected when I run it locally with Docker on my workstation at the IP: http://localhost:8080/ephemeral.server/login.jsp?goto=/ephemeral.server/html/next/index.jsp.
However; when I deploy it to Elastic Beanstalk, I cannot get it to work. The public domain provided times out and I cannot figure out why. I have tried to access both on port 8080 and port 80. For example, I take the Domain created for the environment and try to access my site. First tried 8080:
http://<beanstalk-app>.eba-8ebiumxm.us-east-1.elasticbeanstalk.com:8080/ephemeral.server/login.jsp?goto=/ephemeral.server/html/next/index.jsp
Then I try on port 80:
http://<beanstalk-app>.eba-8ebiumxm.us-east-1.elasticbeanstalk.com/ephemeral.server/login.jsp?goto=/ephemeral.server/html/next/index.jsp
Response is always:
“This site can’t be reached….refused to connect.
Try: Checking the connection”
Step 1: Build the Container (Docker run, Docker build):
FROM --platform=linux/amd64 registry.access.redhat.com/ubi9/ubi:latest
# Install necessary packages
RUN dnf update -y &&
dnf install -y tar gzip unzip
# Add the JRE
COPY jre-8u411-linux-x64.tar.gz /opt/
# COPY and overwrite the catalina.properties
COPY catalina.properties /opt/
# Copy Server installer.
COPY Server.Installer.7.7.2.4484_linux.zip /opt
# Add the server.xml
ADD server.xml /opt
# Add Tomcat
COPY apache-tomcat-9.0.91.tar.gz /opt/
# Unzip the Installer.
RUN unzip /opt/Server.Installer.7.7.2.4484_linux.zip -d /opt
# Give run permissions to install script.
RUN chmod +x /opt/Server.Installer.7.7.2.4484_linux/install.sh
# Make an jre directory in opt and extract the contents
RUN mkdir -p /opt/jre && tar -xvf /opt/jre-8u411-linux-x64.tar.gz -C /opt/jre --strip-components=1
# Set JAVA_HOME and PATH
ENV JAVA_HOME /opt/jre
ENV PATH $JAVA_HOME/bin:$PATH
# Extract Tomcat
RUN tar -xvf /opt/apache-tomcat-9.0.91.tar.gz -C /opt
# Rename Tomcat
RUN mv /opt/apache-tomcat-9.0.91 /opt/tomcat
# Overwrite the server.xml with the connector properties.
RUN mv /opt/server.xml /opt/tomcat/conf/
# Overwrite the catalina.properties with custom properties.
RUN mv /opt/catalina.properties /opt/tomcat/conf/catalina.properties
# Remove the old tomcat directory.
RUN rm /opt/apache-tomcat-9.0.91.tar.gz
# Create tomcat group and user
RUN groupadd tomcat
&& useradd -M -s /sbin/nologin -g tomcat tomcat
# Change ownership of the Tomcat directory
RUN chown -R tomcat:tomcat /opt/tomcat
RUN ls -l /opt/tomcat/lib/
# Set environment variables
ENV CATALINA_PID=/opt/tomcat/temp/tomcat.pid
ENV CATALINA_HOME=/opt/tomcat
ENV CATALINA_BASE=/opt/tomcat
ENV CATALINA_OPTS="-Xms512M -Xmx1024M -server -XX:+UseParallelGC"
ENV evolven_server_root=/opt/tomcat
ENV EVOLVEN_SERVER_ROOT=/opt/tomcat
# Expose Tomcat port
EXPOSE 8080
# RUN mv /opt/Server.Installer.7.7.2.4484_linux/lib/*.jar /opt/tomcat/lib/
# Install it!
# RUN /bin/bash -c 'source /etc/environment && ./opt/Server.Installer.7.7.2.4484_linux/install.sh -t /opt/tomcat -d $DB_HOST -p 5432 -u $DB_USER -P $DB_PASSWORD -c $DB_NAME'
RUN ./opt/Server.Installer.7.7.2.4484_linux/install.sh -t /opt/tomcat -d someurl.rds.xxxxxx.us-east-1.rds.amazonaws.com -p 5432 -u postgres -P <omitted> -c postgres
# RUN rm -rf /opt/Server.Installer.7.7.2.4484_linux/
# Remove the Evolven Server Installer.
RUN rm /opt/Server.Installer.7.7.2.4484_linux.zip
# Remove the JRE
RUN rm /opt/jre-8u411-linux-x64.tar.gz
# Run Tomcat
# ENTRYPOINT ["/opt/tomcat/bin/catalina.sh", "run"]
# CMD ["/opt/tomcat/bin/catalina.sh", "run"]
# CMD ["tail", "-f", "/dev/null"]
USER tomcat
CMD ["/bin/bash", "-c", "/opt/tomcat/bin/catalina.sh start && tail -f /opt/tomcat/logs/catalina.out"]
Step 2: Created a Dockerrun.aws.json file referencing my Docker app like this:
{
"AWSEBDockerrunVersion": "1",
"Image": {
"Name": "myrepo/tomcat-image",
"Update": "true"
},
"Ports": [
{
"ContainerPort": "8080"
}
]
}
Step 3: Then I run: “eb init”, “eb create my-tomcat-env”, “eb deploy”.
I looked at the security group and attached to the EC2 instance hosting my Beanstalk instance and opened an inbound port on 8080.
What else can I do to debug this?
Was able to get it working first thing that was the issue was adding a port mappings, and sizing.
- Port Mappings: Mapped the containerPort to port 80.
- Sizing: Changed the profile to m5.2xlarge from t3.micro (my app requires A LOT more memory than a t3.micro instance).
Here’s my updated Dockerrun.aws.json.
{
"AWSEBDockerrunVersion": "1",
"Image": {
"Name": "bronette/tomcat-app",
"Update": "true"
},
"Ports": [
{
"hostPort": 80,
"containerPort": 8080
}
],
"Volumes": [],
"Logging": "/var/log/nginx"
}