简体   繁体   English

用于tomcat的Dockerfile

[英]Dockerfile for tomcat

我需要创建一个带有tomcat安装细节的图像。我在网上尝试了很多dockerfile并尝试构建但没有运气。任何人都可以告诉我在dockerfile中为了成功的tomcat安装应该是什么命令?。我不需要任何官方的tomcat图像。提前致谢。

This is what i did to solve this: 这就是我解决这个问题的方法:

Dockerfile 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 如果您也想要它,请将以下内容添加到您的上下文和tomcat-users文件中

Context.xml 的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.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

There are several available options for using Tomcat in Docker. 在Docker中使用Tomcat有几个可用选项。 Eg there are the official versions that you can find on https://registry.hub.docker.com/_/tomcat/ 例如,您可以在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

docker build -t my/tomcat .

To start the container you must mount a volume with your war-file. 要启动容器,您必须使用war文件装入卷

docker run -v /somefolder/myapp:/var/lib/tomcat7/webapps/myapp -p 8080:8080 my/tomcat

Then you should be all set! 那么你应该全力以赴!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM