我有一个 Red Hat Enterprise Docker 容器,在其中安装 Tomcat 并运行自定义 Tomcat 应用程序。我希望将其部署到 Elastic Beanstalk。当我在工作站上使用 Docker 在 IP 上本地运行该应用程序时,该应用程序按预期工作:http://localhost:8080/ephemeral.server/login.jsp?goto=/ephemeral.server/html/next/index.jsp。
但是;当我将其部署到 Elastic Beanstalk 时,我无法让它工作。提供的公共领域超时,我不明白为什么。我尝试在端口 8080 和端口 80 上访问。例如,我采用为环境创建的域并尝试访问我的站点。第一次尝试8080:
http://<beanstalk-app>.eba-8ebiumxm.us-east-1.elasticbeanstalk.com:8080/ephemeral.server/login.jsp?goto=/ephemeral.server/html/next/index.jsp
然后我尝试端口 80:
http://<beanstalk-app>.eba-8ebiumxm.us-east-1.elasticbeanstalk.com/ephemeral.server/login.jsp?goto=/ephemeral.server/html/next/index.jsp
回复始终是:
“无法访问此站点....拒绝连接。 尝试:检查连接”
第 1 步:构建容器(Docker 运行、Docker 构建):
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"]
第 2 步:创建一个引用我的 Docker 应用程序的 Dockerrun.aws.json 文件,如下所示:
{
"AWSEBDockerrunVersion": "1",
"Image": {
"Name": "myrepo/tomcat-image",
"Update": "true"
},
"Ports": [
{
"ContainerPort": "8080"
}
]
}
第 3 步:然后运行:“eb init”、“eb create my-tomcat-env”、“eb deploy”。
我查看了安全组并附加到托管我的 Beanstalk 实例的 EC2 实例,并在 8080 上打开了入站端口。
我还能做什么来调试这个?
能够让它工作的第一件事就是添加端口映射和大小调整。
这是我更新的 Dockerrun.aws.json。
{
"AWSEBDockerrunVersion": "1",
"Image": {
"Name": "bronette/tomcat-app",
"Update": "true"
},
"Ports": [
{
"hostPort": 80,
"containerPort": 8080
}
],
"Volumes": [],
"Logging": "/var/log/nginx"
}