<span style="font-family:Courier New;"><span style="font-family:Courier New;"># Sample Dockerfile for a Java webapp running on Tomcat + Apache
FROM centos:centos7
MAINTAINER SHEN.GANG (gang.shen@chivox.com)
# Other stuff can be installed with yum
# (Note that git is quite old. If you want 1.8.x, install from source.)
ADD ./etc/nginx.repo /etc/yum/repos.d/nginx.repo
RUN yum -y --noplugins --verbose update
RUN yum -y --noplugins --verbose install nginx git wget tar
RUN yum -y install vim net-tools libaio perl-Data-Dumper
# Java 7
ADD ./jdk /tmp
RUN chmod +x /tmp/jdk-7u71-linux-x64.rpm
RUN rpm -i /tmp/jdk-7u71-linux-x64.rpm
RUN rm -rf /tmp/jdk-7u71-linux-x64.rpm
# Copy start script
ADD ./start-script /usr/local/start-script
RUN chmod +x /usr/local/start-script/start.sh
RUN chmod +x /usr/local/start-script/init.sh
# Copy my-app
ADD ./my-app /home/my-app
# mysql 5.1
ADD ./mysql /tmp
RUN chmod +x /tmp/MySQL-server-community-5.1.73-1.rhel5.x86_64.rpm
RUN chmod +x /tmp/MySQL-client-community-5.1.73-1.rhel5.x86_64.rpm
RUN rpm -ivh /tmp/MySQL-server-community-5.1.73-1.rhel5.x86_64.rpm
RUN rpm -ivh /tmp/MySQL-client-community-5.1.73-1.rhel5.x86_64.rpm
RUN rm -rf /tmp/MySQL-server-community-5.1.73-1.rhel5.x86_64.rpm
RUN rm -rf /tmp/MySQL-client-community-5.1.73-1.rhel5.x86_64.rpm
# mysql start
RUN /usr/local/start-script/init.sh
# Tomcat 7
ADD ./tomcat /tmp
RUN cd /usr/local && tar xzf /tmp/apache-tomcat-7.0.53.tar.gz
RUN ln -s /usr/local/apache-tomcat-7.0.53 /usr/local/tomcat
RUN rm /tmp/apache-tomcat-7.0.53.tar.gz
# Maven
ADD ./maven /tmp
RUN cd /usr/local && tar xzf /tmp/apache-maven-3.1.1-bin.tar.gz
RUN ln -s /usr/local/apache-maven-3.1.1 /usr/local/maven
RUN rm /tmp/apache-maven-3.1.1-bin.tar.gz
# Copy nginx config file and delete conflicting conf
ADD ./nginx-conf /etc/nginx/conf.d
RUN rm -f /etc/nginx/conf.d/default.conf
# Environment variables
ENV JAVA_HOME /usr/java/latest
ENV CATALINA_HOME /usr/local/tomcat
ENV MAVEN_HOME /usr/local/maven
# Set the start script as the default command (this will be overriden if a command is passed to Docker on the commandline).
# Note that we tail Tomcat's log in order to keep the process running
# so that Docker will not shutdown the container. This is a bit of a hack.
CMD /usr/local/start.sh && tail -F /usr/local/tomcat/logs/catalina.out
# Forward HTTP ports
EXPOSE 80 8080 3306
</span></span>
init.sh
<span style="font-family:Courier New;">#!/bin/bash
#/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
/etc/init.d/mysql restart
sleep 5
mysqladmin -u root password '123456'
echo "success to set the root password"
mysql -uroot -p123456 -e "GRANT ALL PRIVILEGES ON *.* TO root@\"%\" IDENTIFIED BY '123456';flush privileges;"
mysql -u root -p123456 < /home/my-app/zscp3_dz.sql
echo "success to import the sql script"
</span>
<span style="font-family:Courier New;">#!/bin/sh
#mysql service
/etc/init.d/mysql restart
# Start Tomcat
$CATALINA_HOME/bin/startup.sh
# Start nginx
nginx
</span>
nginx.conf
<span style="font-family:Courier New;">server {
listen 80;
server_name localhost;
location / {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:8080/;
}
}
</span>
<span style="font-size:18px;">[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1</span>