Dockerfile的一些demo

YatHo發表於2017-10-25

tomcat7.0_jdk1.6

#繼承使用者建立的sshd映象
FROM yatho:sshd_ubuntu

#建立者的基本資訊 MAINTAINER yatho (yat_ho@163.com)
#設定環境變數,所有操作都是非互動式的 ENV DEBIAN_FRONTEND noninteractive
#系統時區設定 RUN echo "Asia/Shanghai" > /etc/timezone && \ dpkg-reconfigure -f noninteractive tedate
#安裝跟tomcat使用者認證相關的軟體 RUN apt-get install -yq --no-install-recommends wget pwgen ca-certificates && \ apt-get clean && \ rm -rf /var/lib/apt/lists/*
#設定tomcat的環境變數,若讀者有其他的環境變數需要設定,也可以新增 ENV CATALINA_HOME /tomcat ENV JAVA_HOME /jdk
#複製tomcat和jdk檔案到映象中 ADD apache-tomcat-7.0.56 /tomcat ADD JAVA_HOME /jdk ADD create_tomcat_admin_user.sh /create_tomcat_admin_user.sh ADD run.sh /run.sh RUN chmod +x /*.sh RUN chmod +x /tomcat/bin/*.sh EXPOSE 8080 CMD ["/run.sh"]
#!/bin/bash

if [ -f /.tomcat_admin_created ]; then
    echo "Tomcat 'admin' user already created"
    exit 0
fi

#generate password
PASS=${TOMCAT_PASS:-$(pwgen -s 12 1)}
_word=$( [ ${TOMCAT_PASS} ] && echo "preset" || echo "random" )

echo "=> Creating and admin user with a ${_word} password in Tomcat"
sed -i -r 's/<\/tomcat-users>//' ${CATALINA_HOME}/conf/tomcat-users.xml
echo '<role rolename="manager-gui"/>' >> ${CATALINA_HOME}/conf/tomcat-users.xml
echo '<role rolename="manager-script"/>' >> ${CATALINA_HOME}/conf/tomcat-users.xml
echo '<role rolename="manager-jmx"/>' >> ${CATALINA_HOME}/conf/tomcat-users.xml
echo '<role rolename="admin-gui"/>' >> ${CATALINA_HOME}/conf/tomcat-users.xml
echo '<role rolename="admin-script"/>' >> ${CATALINA_HOME}/conf/tomcat-users.xml
echo "<user username=\"admin\" password=\"${PASS}\" roles=\"manager-gui,manager-script,manager-jmx,admin-gui, admin-script\"/>" >> ${CATALINA_HOME}/conf/tomcat-users.xml
echo '</tomcat-users>' >> ${CATALINA_HOME}/conf/tomcat-users.xml
echo "=> Done!"
touch /.tomcat_admin_created

echo "========================================================================"
echo "You can now configure to this Tomcat server using:"
echo ""
echo "    admin:${PASS}"
echo ""
echo "========================================================================"

  

run.sh 指令碼檔案  

#!/bin/bash

if [ ! -f /.tomcat_admin_created ]; then
    /create_tomcat_admin_user.sh
fi
/usr/sbin/sshd -D &
exec ${CATALINA_HOME}/bin/catalina.sh run

  

http://blog.csdn.net/smallfish1983/article/details/40543821

相關文章