CentOS 7基于Docker的JDK7 + MySQL + Tomcat + Nginx + Maven环境


<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>


start.sh

<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>


nginx.repo

<span style="font-size:18px;">[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1</span>




  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sg_0504

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值