我想创建一个 docker 容器来在其中安装 Tomcat。看来我的 docker 编译没有问题,并且我也能够运行 tomcat 而没有通过日志报告任何问题。但是,如果我尝试打开 tomcat,我会收到 404 错误。我不知道我错过了什么。请问有什么想法吗?接下来是我的 Dockerfile 的内容:
FROM centos:7
MAINTAINER joseccz
EXPOSE 8080
EXPOSE 8009
RUN yum install -y mc
RUN yum install -y wget
# RUN yum install -y apr-devel openssl-devel
RUN yum install -y gcc
RUN yum install epel-release -y
RUN yum install dnf -y
RUN yum install net-tools -y
RUN yum install libtool -y
ENV JAVA_HOME /opt/javaSDK
ENV JRE_HOME ${JAVA_HOME}/jre
ADD javaSDK ${JAVA_HOME}
ADD tomcat.service /etc/systemd/system/
# ----------------------------------------------- Copy Tomcat Files to /opt/tomcat -----------------------------------------------
ENV TOMCAT_MAJOR 8
ENV TOMCAT_VERSION 8.5.45
ENV CATALINA_HOME /opt/tomcat
# http://www-us.apache.org/dist/tomcat/tomcat-8/v8.5.45/bin/apache-tomcat-8.5.45.tar.gz
ENV PATH $JAVA_HOME/bin:$CATALINA_HOME/bin:$CATALINA_HOME/lib:$PATH
RUN wget http://www-us.apache.org/dist/tomcat/tomcat-${TOMCAT_MAJOR}/v${TOMCAT_VERSION}/bin/apache-tomcat-${TOMCAT_VERSION}.tar.gz && \
tar -xvf apache-tomcat-${TOMCAT_VERSION}.tar.gz
RUN mv apache-tomcat-${TOMCAT_VERSION} tomcat
RUN rm apache-tomcat*.tar.gz
RUN mv tomcat /opt/tomcat
# --------------------------------------------------------------------------------------------------------------------------------
RUN groupadd tomcat
RUN useradd -s /bin/nologin -g tomcat -d /opt/tomcat tomcat
# RUN wget https://rpmfind.net/linux/mageia/distrib/cauldron/x86_64/media/core/release/tomcat-native-1.2.23-1.mga8.x86_64.rpm
# RUN rpm -i tomcat-native-1.2.23-1.mga8.x86_64.rpm
# RUN cd /opt/tomcat
RUN chgrp -R tomcat /opt/tomcat/conf
RUN chmod g+rwx /opt/tomcat/conf
RUN chmod g+r /opt/tomcat/conf/*
RUN chown -R tomcat /opt/tomcat/logs/ /opt/tomcat/temp/ /opt/tomcat/webapps/ /opt/tomcat/work/
RUN chgrp -R tomcat /opt/tomcat/bin
RUN chgrp -R tomcat /opt/tomcat/lib
RUN chmod g+rwx /opt/tomcat/bin
RUN chmod g+r /opt/tomcat/bin/*
#----------------------------------Create /opt/software folder for addinitonal soft needed by Tomcat ------------------------------
RUN mkdir /opt/software
#---------------------------------------- copy and compile Development tools ---------------------------------------------------------
RUN yum groupinstall "Development Tools" -y
#---------------------------------------- Donwload and install open ssl ------------------------------------------------------------
RUN wget https://www.openssl.org/source/openssl-1.0.2l.tar.gz
RUN tar -xvf openssl-1.0.2l.tar.gz
RUN mv openssl-1.0.2l openssl
RUN mv openssl /opt/software/openssl
RUN cd /opt/software/openssl && ./config -fPIC --prefix=/opt/software/ --openssldir=/opt/software/ && make && make install
#---------------------------------------- Donwload and install open apr ------------------------------------------------------------
ENV APRVERSION 1.6.5
RUN wget http://apache.mirrors.ionfish.org//apr/apr-${APRVERSION}.tar.gz
RUN tar -xvf apr-${APRVERSION}.tar.gz
RUN mv apr-${APRVERSION} apr
RUN mv apr /opt/software/apr
RUN cd /opt/software/apr/ && \
./configure --prefix=/opt/software/ && \
make && make install
#------------------------------------------ Copy TOMCAT native
# compiling tomcat native
RUN cd ${CATALINA_HOME}/bin/ && \
tar -xvf tomcat-native.tar.gz && \
cd tomcat-native-1.2.23-src/native/ && \
./configure --with-apr=/opt/software/ --with-java-home=/opt/javaSDK/ --with-ssl=/opt/software --prefix=/opt/tomcat && \
make && \
make install
ADD setenv.sh /opt/tomcat/bin/
我的 setenv.sh 文件内容是:
export JAVA_HOME=/opt/javaSDK
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CATALINA_HOME/lib
export LD_LIBRARY_PATH
重要的部分是以某种方式将下一个 xommands 添加到 dockerfile:
tomcat-native.tar.gz必须是tomca安装压缩文件中包含的要安装的Tomcat版本中包含的那个。此外,安装文件中包含的 Tomcat 应用程序示例必须至少手动添加到 Tomcat 的 webapps 文件夹中。我在自动执行此操作时遇到了问题。