centOSベースで、apacheをフロントに置き、ajp経由でtomcat javaアプリケーションに繋ぐコンテナを作成したかった。Dockerイメージをapacheベースでやったり、tomcatベースでやったりしたけど結局centOSから自分で載せるものを入れていく方が確実だという結論に。
※こちらを参考にさせて頂きました。
FROM centos:centos6
WORKDIR /tmp/
# yum httpd/wget/java のインストール
RUN yum -y install httpd wget java-1.8.0-openjdk
# apache 設定
RUN chown -R apache.apache /var/www/html/
# Dockerfile配置Dirに初期設定するファイルは一式置いておき、それをコピー
COPY ./serverconf/httpd.conf /etc/httpd/conf/httpd.conf
# tomcat 設定
RUN wget http://archive.apache.org/dist/tomcat/tomcat-6/v6.0.39/bin/apache-tomcat-6.0.39.tar.gz
RUN tar zxvf apache-tomcat-6.0.39.tar.gz
RUN mv apache-tomcat-6.0.39 /usr/local/tomcat6
RUN cp /usr/local/tomcat6/bin/catalina.sh /etc/init.d/tomcat6
RUN chmod 775 /etc/init.d/tomcat6
ENV CATALINA_HOME=/usr/local/tomcat6
ENV CATALINA_BASE=/usr/local/tomcat6
ENV CATALINA_TMPDIR=/usr/local/tomcat6/temp
ENV JRE_HOME=/usr
ENV CLASSPATH=/usr/local/tomcat/bin/bootstrap.jar
COPY ./serverconf/server.xml /usr/local/tomcat6/conf/server.xml
RUN mkdir /home/webapps
COPY ./hogeapps /home/webapps/hogeapps
#httpd,tomcat6の起動スクリプトの作成
RUN echo -e "/etc/init.d/httpd start\n/etc/init.d/tomcat6 start\n/bin/bash" > /startService.sh
#httpd,tomcat6の起動スクリプトの権限設定
RUN chmod o+x /startService.sh
#公開ポート(apache:80,tomcat(http):8888で空けてる)
EXPOSE 80 8888
#httpd,tomcat6の起動スクリプトの実行
CMD /startService.sh
apache conf
httpd.conf
ServerRoot "/etc/httpd/"
Listen 80
#LoadModule authn_file_module modules/mod_authn_file.so
#LoadModule authn_dbm_module modules/mod_authn_dbm.so
~~(省略)~~
User apache
Group apache
RewriteEngine on
ProxyPass / ajp://localhost:8002/
server.xml
server.xml
<?xml version='1.0' encoding='utf-8'?>
<Server port="8001" shutdown="SHUTDOWN">
<!--APR library loader. Documentation at /docs/apr.html -->
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
<Listener className="org.apache.catalina.core.JasperListener" />
<!-- Prevent memory leaks due to use of particular java/javax APIs-->
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html -->
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<GlobalNamingResources>
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>
<Service name="Catalina">
<Connector port="8888" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Connector port="8002" protocol="AJP/1.3"
redirectPort="8003" useBodyEncodingForURI="true"
maxProcessors="160" minProcessors="5"
acceptCount="100" debug="0" connectionTimeout="20000" />
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Context path="/" docBase="/home/webapps/hogeapps">
...
</Context>
</Host>
</Engine>
</Service>
</Server>
docker build
docker build -t hoge/huga:latest .
docker run
docker run -itd --rm -p 8080:80 -p 8888:8888 hoge/huga:latest