Search code examples
debiantomcat7dockerboot2docker

Tomcat7 in debian:wheezy Docker instance fails to start


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?


Solution

  • 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/