I need to create an image with tomcat installation details.I tried many dockerfile in net and tried to build but no luck.Can anybody tell me what commands should be their in dockerfile for a successfull tomcat installation?.I dont need any official tomcat image.Thanks in advance.
Asked
Active
Viewed 5.6k times
3
-
1Have a look at [these Dockerfiles](https://github.com/tutumcloud/tutum-docker-tomcat) – joh.scheuer Dec 31 '14 at 10:12
-
You can use these as a starting point as well: https://github.com/docker-library/tomcat – guido.rota Dec 31 '14 at 11:05
2 Answers
9
This is what i did to solve this:
Dockerfile
FROM tomcat
MAINTAINER richard
RUN apt-get update && apt-get -y upgrade
WORKDIR /usr/local/tomcat
COPY tomcat-users.xml /usr/local/tomcat/conf/tomcat-users.xml
COPY context.xml /usr/local/tomcat/webapps/manager/META-INF/context.xml
EXPOSE 8080
I'm copying those two files in order to access the manager app from outside. If you want it too, add the following to your context and tomcat-users files
Context.xml
<Context antiResourceLocking="false" privileged="true" >
<!-- <Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" /> -->
<Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
</Context>
tomcat-users.xml
<tomcat-users xmlns="http://tomcat.apache.org/xml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"
version="1.0">
<user username="admin" password="secret" roles="manager-gui"/>
</tomcat-users>
Then you can build it and run it:
docker build -t name/tomcat .
docker run -d -p 8080:8080 --name some_name name/tomcat
Deploy your application as follows:
docker cp some/app.war some_name:/usr/local/tomcat/webapps/app.war

Richard
- 719
- 10
- 11
-
it works, except the deployment. War file is not getting deployed into tomcat. – CrazyProgrammer Dec 29 '18 at 07:44
6
There are several available options for using Tomcat in Docker. E.g. there are the official versions that you can find on https://registry.hub.docker.com/_/tomcat/
But, If you want to create a file from scratch the following could be of help:
FROM ubuntu:14.04
RUN apt-get update && apt-get -y upgrade
RUN apt-get -y install software-properties-common
RUN add-apt-repository ppa:webupd8team/java
RUN apt-get -y update
# Accept the license
RUN echo "oracle-java7-installer shared/accepted-oracle-license-v1-1 boolean true" | debconf-set-selections
RUN apt-get -y install oracle-java7-installer
# Here comes the tomcat installation
RUN apt-get -y install tomcat7
RUN echo "JAVA_HOME=/usr/lib/jvm/java-7-oracle" >> /etc/default/tomcat7
# Expose the default tomcat port
EXPOSE 8080
# Start the tomcat (and leave it hanging)
CMD service tomcat7 start && tail -f /var/lib/tomcat7/logs/catalina.out
To build the image simply use docker build:
docker build -t my/tomcat .
To start the container you must mount a volume with your war-file.
docker run -v /somefolder/myapp:/var/lib/tomcat7/webapps/myapp -p 8080:8080 my/tomcat
Then you should be all set!

wassgren
- 18,651
- 6
- 63
- 77
-
-
It also failed for me. I would like information about how to look at logs, etc. also if this can be gotten to run. – Jeff Feb 22 '16 at 00:23
-
to debug: try to ssh into the container, without starting tomcat: [docker run -v /somefolder/myapp:/var/lib/tomcat7/webapps/myapp -p 8080:8080 -it my/tomcat bash ] in the above command, verify if your app folder is correctly specified -v /somefolder/myapp:/var/lib/tomcat7/webapps/myapp then, try to start tomcat service and see what is happening.... – srikanth Nutigattu May 05 '16 at 16:13
-
This worked perfectly for me on Ubuntu 16.04 and was very helpful for me to learn about why services are a bad idea in a container. The line to get the ppa for Java 1.8 was a huge help - but the most important line above is: `CMD service tomcat7 start && tail -f /var/lib/tomcat7/logs/catalina.out` because it leaves the service running. I had to add the "-d" and the "--cap-add SYS_PTRACE" flags to the run command. – Ted Cahall Mar 11 '18 at 10:49