且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Tomcat7在debian中:wheezy Docker实例无法启动

更新时间:2023-01-17 23:39:24

我尝试了你的步骤,能够运行tomcat 。我没有得到apt-get的问题,所以现在需要使用 apt-get update --fix-missing 。我甚至从init.d脚本启动tomcat,它的工作。



我的猜测是,你有一些网络问题,或者Debian的存储库有一些问题,但是他们已经修复了。



无论如何,您应该注意,只要指定的命令正在运行,容器就会运行。这意味着你应该在前台运行tomcat,或者以另一种方式确保同一件事情。您可以查看此答案了解某些选项。





我已经创建了一个 Dockerfile 来测试这个。这里是:

  FROM google / debian:wheezy 

运行apt-get update
运行apt-get install -y openjdk-7-jre tomcat7

添加run.sh /root/run.sh
运行chmod + x /root/run.sh

EXPOSE 8080

CMD [/root/run.sh]

这里是它使用的 run.sh 脚本:

 #!/ bin / bash 

/etc/init.d/tomcat7 start

#只要脚本运行,容器就会运行,这就是为什么
#我们需要一些长期的东西
exec tail -f /var/log/tomcat7/catalina.out

以下是一个示例构建和运行会话:

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

现在你应该能够看到tomcat的It works!页面 http:// localhost:8080 /


I'm trying to build a docker image for the first time using a debian image from Google (google/debian:wheezy), setting up OpenJDK7 on it and trying to setup Tomcat7.

docker pull google/debian:wheezy
docker run -i -t google/debian:wheezy bash

Once I'm in bash, I install openjdk with

apt-get update
apt-get install openjdk-7-jre

After a while, I get an error and I must run

 apt-get update --fix-missing
 apt-get install openjdk-7-jre
 apt-get install tomcat7

After Tomcat7 is installed, I try to start it with

/etc/init.d/tomcat7 start

Which gives me the following error:

[FAIL] Starting Tomcat servlet engine: tomcat7 failed!

I'm obviously doing something wrong, I'm getting the exact same behaviour on both my Debian Docker installation and my OSX Docker installation (at least it's consistent, that's kinda impressive!)

Looking in /var/log/catalina.out doesn't show any errors, neither does the localhost logs.

I've followed the same process with a normal debian:wheezy image and getting exactly the same failure without any errors. Any idea where I'm screwing up?

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/