-1

I have started learning docker and having hard time getting a tomcat container setup manually. The idea is to create an image manually and then translate the steps into a docker file. Listing steps performed so far.

     Using aws EC2 Centos micro instance for learning docker
     Docker daemon is up and running
     Docker usergroup has also been setup and I run docker as normal user
     Installed oracle JDK as below:
               wget --no-cookies --no-check-certificate --header "Cookie:\
               gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; \
               oraclelicense=accept-securebackup-cookie" \
               http://download.oracle.com/otn-pub/java/jdk/8u91-b14/jdk-8u91-linux-x64.rpm'
     Installed tomcat using yum ( Have tried manual method using the gz file also but did not help ):
               yum install tomcat.noarch tomcat-admin-webapps.noarch tomcat-webapps.noarch
     Edited "/etc/tomcat/tomcat.conf" to add /usr/java/latest as JAVA_HOME
     Committed the changes to container:
               docker commit 42b0beb497f9 $USER/tomcat_install
      docker run -d -p 8080:8080 $USER/tomcat_install /usr/sbin/tomcat start -D FOREGROUND
               Output: SHA Checksum

But the container exits giving the error below:

      `enter code here /usr/sbin/tomcat: line 21: .: /etc/sysconfig/: is a directory`

Upon relevant searches I found out that this errors comes because of open jdk use instead of oracle jdk. As above, i started using oracle jdk.

Please note: Since I am learning, i do not want to download official tomcat image and use it since it makes it too easy. Although for comparison i did download that image but still unable to resolve the issue. Some suggestions to resolve this and have my own tomcat image would be awesome

f-z-N
  • 1,645
  • 4
  • 24
  • 38
  • Not sure why this was downvoted? Does it not show any research done prior to posting here? – f-z-N Aug 17 '16 at 08:42

1 Answers1

1

I was facing the very same issue today. Here is what I found: if you look at /usr/sbin/tomcat, you will see that it needs $NAME="tomcat" around line 21

# Get instance specific config file
if [ -r "/etc/sysconfig/${NAME}" ]; then
    . /etc/sysconfig/${NAME}
fi

which is required to load /etc/sysconfig/tomcat. It also needs $CATALINA_BASE="/usr/share/tomcat" in the statement starting at line 39

    if [ "$1" = "start" ]; then
      ${JAVACMD} $JAVA_OPTS $CATALINA_OPTS \
        -classpath "$CLASSPATH" \
        -Dcatalina.base="$CATALINA_BASE" \
        -Dcatalina.home="$CATALINA_HOME" \
        -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" \
        -Djava.io.tmpdir="$CATALINA_TMPDIR" \
        -Djava.util.logging.config.file="${CATALINA_BASE}/conf/logging.properties" \
        -Djava.util.logging.manager="org.apache.juli.ClassLoaderLogManager" \
        org.apache.catalina.startup.Bootstrap start \
        >> ${CATALINA_BASE}/logs/catalina.out 2>&1 &
        if [ ! -z "$CATALINA_PID" ]; then
          echo $! > $CATALINA_PID
        fi

So it can know where to write the log file catalina.out. So, what I did was to define the two variables (easy to do in your Dockerfile)

NAME="tomcat"
CATALINA_BASE="/usr/share/tomcat"

in /etc/tomcat/tomcat.conf and thne I was able to manually start tomcat

[root@tomcat tomcat]# ps -ef|grep tomcat
root       352     1  8 13:09 ?        00:00:01 /usr/lib/jvm/jre/bin/java -classpath /usr/share/tomcat/bin/bootstrap.jar:/usr/share/tomcat/bin/tomcat-juli.jar:/usr/share/java/commons-daemon.jar -Dcatalina.base=/usr/share/tomcat -Dcatalina.home=/usr/share/tomcat -Djava.endorsed.dirs= -Djava.io.tmpdir=/var/cache/tomcat/temp -Djava.util.logging.config.file=/usr/share/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager org.apache.catalina.startup.Bootstrap start
root       372     1  0 13:09 ?        00:00:00 grep --color=auto tomcat
[root@tomcat tomcat]#

Is this the proper way? I don't know, but it works.

I put a longer winded version of this answer at http://unixwars.blogspot.com/2016/07/starting-tomcat-manually-in-docker.html if you are curious. However, I hope what is in this reply suffices.

raubvogel
  • 41
  • 4