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?
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 :
Thus you can start tomcat in the Dockerfile.
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:And here is the
run.sh
script that it uses:Here is a sample build and run session:
Now you should be able to see tomcat's "It works !" page on
http://localhost:8080/
Under Ubuntu:Trusty following docker run options resolved issue with tomcat start ( start-stop-daemon actualy)