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.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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
回答2:
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!