Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dockerfile for tomcat

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.

like image 248
user2451997 Avatar asked Oct 20 '25 04:10

user2451997


2 Answers

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
like image 54
Richard Avatar answered Oct 21 '25 22:10

Richard


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!

like image 28
wassgren Avatar answered Oct 21 '25 21:10

wassgren



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!