简体   繁体   中英

Tomcat freezes in Docker container when starting

Here's the thing. I have the following Dockerfile:

DOCKERFILE

FROM centos:centos7
MAINTAINER Legos
ADD epel-release-7-9.noarch.rpm /etc/extras/epel-release-7-9.noarch.rpm
RUN rpm -Uvh /etc/extras/epel-release*rpm

# Install prepare infrastructure
RUN yum -y update && \
yum -y install wget && \
yum -y install tar && \ 
yum -y install haveged && \
yum -y install rng-tools

RUN chkconfig haveged on

# Prepare environment 
ADD jdk* /opt/
WORKDIR /opt/
RUN yum localinstall -y "jdk-8u131-linux-x64.rpm"
RUN echo "1"|alternatives --config java
ENV JAVA_HOME /usr/java/jdk1.8.0_131
#ENV JAVA_OPTS "-Djava.security.egd=/dev/./urandom"

ENV CATALINA_HOME /opt/tomcat 
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/bin:$CATALINA_HOME/scripts

# Install Tomcat
ENV TOMCAT_MAJOR 8
ENV TOMCAT_VERSION 8.5.15

RUN wget http://www-eu.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 && \
rm apache-tomcat*.tar.gz && \
mv apache-tomcat* ${CATALINA_HOME}

RUN chmod +x ${CATALINA_HOME}/bin/*sh

# Create Tomcat admin user
ADD create_admin_user.sh $CATALINA_HOME/scripts/create_admin_user.sh
ADD tomcat.sh $CATALINA_HOME/scripts/tomcat.sh

ADD webapps/gireUsuarios.war $CATALINA_HOME/webapps/gireUsuarios.war
ADD conf/tomcat-users.xml $CATALINA_HOME/conf/tomcat-users.xml
ADD conf/Catalina/localhost/manager.xml $CATALINA_HOME/conf/Catalina/localhost/manager.xml

RUN chmod +x $CATALINA_HOME/scripts/*.sh

# Create tomcat user
RUN groupadd -r tomcat && \
useradd -g tomcat -d ${CATALINA_HOME} -s /sbin/nologin  -c "Tomcat user" tomcat && \
chown -R tomcat:tomcat ${CATALINA_HOME}

WORKDIR /opt/tomcat

EXPOSE 8080 8009 8443 9100-9120 4369 80

RUN yum clean all

USER tomcat
CMD ["tomcat.sh"]

TL;DR: It's an image for a CentOS 7 machine with Tomcat 8.5 and Java 1.8. The 'tomcat.sh' just runs catalina.sh after creating a user in the configuration, so there's not much to say about that.

The thing is this: When I create a container, the container freezes while deploying the .war file that I'm passing. I tried both initiating other .war files, with positive results, and I tried deploying this problematic .war file in my machines Tomcat 8.5 (an straight-out-of-the-box Tomcat without much more than the addition of the manager-gui user), and it is deploying successfully.

So, the question: any idea why Tomcat would freeze during deploy in a Docker container? I tried the JAVA_OPTS=-Djava.security.egd=/dev/./urandom solution that's around, that supposedly helps with this kind of happenings, but it didn't work. Suggestions?

Solved it. I added te additional parameters to the JAVA_OPTS and it worked. The final JAVA_OPTS is like this:

-Djava.security.egd=/dev/./urandom -Djava.awt.headless=true -Xmx1024m -XX:MaxPermSize=512m -XX:+UseConcMarkSweepGC

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM