Tomcat7 in debian:wheezy Docker instance fails to start

南楼画角 提交于 2019-12-06 09:59:21
ivant

I tried your steps and was able to run tomcat just fine. I didn't get the problem with apt-get, so now apt-get update --fix-missing was required. I even started tomcat from the init.d script and it worked.

My guess is, that either you had some network problems, or there were some problems with Debian's repositories, but they got fixed.

In any case you should note, that the container is running as long as the specified command is running. That means, that you should either run tomcat in the foreground or ensure the same thing in another way. You can check this answer for some options.

[EDIT]

I've created a Dockerfile to test this. Here it is:

FROM google/debian:wheezy

RUN apt-get update
RUN apt-get install -y openjdk-7-jre tomcat7

ADD run.sh /root/run.sh
RUN chmod +x /root/run.sh

EXPOSE 8080

CMD ["/root/run.sh"]

And here is the run.sh script that it uses:

#!/bin/bash

/etc/init.d/tomcat7 start

# The container will run as long as the script is running, that's why
# we need something long-lived here
exec tail -f /var/log/tomcat7/catalina.out

Here is a sample build and run session:

$ docker build -t tomcat7-test .
$ docker run -d -p 8080:8080 tomcat7-test

Now you should be able to see tomcat's "It works !" page on http://localhost:8080/

You can use service tomcat start in your Dockerfile, just add --privileged=true parameter with docker run command. Tomcat need extended privileges.

More informations there: https://docs.docker.com/reference/run/#runtime-privilege-linux-capabilities-and-lxc-configuration

I would advise you to build your image from a Dockerfile. This is way more explicit, consistent and maintainable, docker will output errors if some arise during the build.

The beginning of the Dockerfile would be, for instance :

FROM google/debian:wheezy
MAINTAINER Jan Vladimir Mostert <JanVladimirMostert@example.com>
RUN apt-get -qq update
RUN apt-get install openjdk-7-jre
RUN apt-get install tomcat7

Thus you can start tomcat in the Dockerfile.

Under Ubuntu:Trusty following docker run options resolved issue with tomcat start ( start-stop-daemon actualy)

docker run -itd --cap-add=SYS_PTRACE --security-opt=apparmor:unconfined mytomcat7image
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!