Tomcat手动设置 - Docker

时间:2016-07-19 05:13:09

标签: tomcat docker

我已经开始学习docker并且很难手动设置tomcat容器。我们的想法是手动创建图像,然后将步骤转换为docker文件。目前已执行的列表步骤。

     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

但容器退出时会出现以下错误:

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

经过相关搜索,我发现这个错误是因为使用open jdk而不是oracle jdk。如上所述,我开始使用oracle jdk。

请注意:由于我正在学习,我不想下载官方的tomcat图像并使用它,因为它太容易了。虽然为了比较我确实下载了该图像,但仍然无法解决问题。解决此问题并拥有自己的tomcat图像的一些建议将非常棒

1 个答案:

答案 0 :(得分:1)

我今天面临同样的问题。这是我发现的:如果你看一下/ usr / sbin / tomcat,你会发现它需要$ NAME =" tomcat"在第21行附近

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

这是加载/ etc / sysconfig / tomcat所必需的。它还需要$ CATALINA_BASE =" / usr / share / tomcat"在第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

因此它可以知道在哪里写日志文件catalina.out。所以,我所做的是定义两个变量(在Dockerfile中很容易)

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

在/etc/tomcat/tomcat.conf中我能够手动启动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]#

这是正确的方法吗?我不知道,但它确实有效。

如果你很好奇,我会在http://unixwars.blogspot.com/2016/07/starting-tomcat-manually-in-docker.html放一个较长的答案版本的答案。但是,我希望本回复中的内容足够。