我想创建一个 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
答案1
重要的部分是以某种方式将下一个 xommands 添加到 dockerfile:
#---------------------------------------- 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.8-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/
tomcat-native.tar.gz 必须是要安装的 Tomcat 版本中包含的版本,该版本包含在 tomca 安装压缩文件中。此外,安装文件中包含的 Tomcat 应用程序示例必须至少手动添加到 Tomcat 的 webapps 文件夹中。我无法自动执行此操作。