将mysql、nginx、zookeeper、redis、tomcat集成为一个docker镜像

将mysql、nginx、zookeeper、redis、tomcat集成为一个docker镜像
实现运行一个镜像,便全部自动化安装启动mysql、nginx、zookeeper、redis、tomcat。

1.在CentOS7上安装Docker
2.复制拷贝相关压缩包到同一个目录
3.拉取centos镜像
4.在压缩包目录下编写Dockerfile

FROM centos:centos7
MAINTAINER wxd "[email protected]"
# 1.准备工作创建文件夹
    RUN \
    mkdir -p /usr/local \
    && mkdir -p /etc/redis \
    && mkdir /opt/logs \
    && mkdir -p /data/mysql \
    && mkdir -p /data/nginx/conf \
    && mkdir -p /data/nginx/html
# 复制文件
COPY jdk-8u181-linux-x64.tar.gz /usr/local
COPY redis-3.2.8.tar.gz /usr/local
COPY apache-tomcat-8.5.34.tar.gz /usr/local
COPY zookeeper-3.4.12.tar.gz /usr/local
COPY zoo.cfg /usr/local
COPY redis.conf /etc/redis/redis.conf
COPY supervisord.conf /etc/supervisord.conf
COPY program.conf /etc/program.conf
# 复制数据库文件
COPY libaio-0.3.109-13.el7.x86_64.rpm /usr/local
COPY MySQL-client-5.6.29-1.rhel5.x86_64.rpm /usr/local
COPY MySQL-devel-5.6.29-1.rhel5.x86_64.rpm /usr/local
COPY MySQL-server-5.6.29-1.rhel5.x86_64.rpm /usr/local
# 复制nginx安装文件
COPY nginx-1.15.5.tar.gz /usr/local
#COPY nginx.conf /usr/local/
#COPY ckkxy.kz38.cn_20180615.tar.gz /usr/local
#安装vim编辑器
RUN yum -y install vim
# 安装 sshd 修改密码
RUN \
    yum install passwd openssl openssh-server -y \
    && ssh-keygen -q -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key -N '' \
    && ssh-keygen -q -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N '' \
    && sed -i "s/UsePAM.*/UsePAM no/g" /etc/ssh/sshd_config \
    && echo 123456 | passwd --stdin root \
    && echo root:123456|chpasswd \
    && rm -rf /var/cache/yum/*
# 安装redis
RUN \
    yum install gcc -y \
    && cd /usr/local \
    && tar -xzf redis-3.2.8.tar.gz \
    && rm -rf redis-3.2.8.tar.gz \
    && cd redis-3.2.8 && yum -y install tcl && make && make install \
    && cd /usr/local \
   # && rm -rf redis-3.2.8 \
    && rm -rf /var/cache/yum/*
# 安装mysql
RUN \
    yum -y install perl perl-devel perl-Module-Install.noarch net-tools \
    && cd /usr/local \
    && rpm -ivh libaio-0.3.109-13.el7.x86_64.rpm \
    && rpm -ivh MySQL-server-5.6.29-1.rhel5.x86_64.rpm \
    && rpm -ivh MySQL-client-5.6.29-1.rhel5.x86_64.rpm \
    && rpm -ivh MySQL-devel-5.6.29-1.rhel5.x86_64.rpm \
    && chown -R mysql:mysql /data/mysql \
    && /etc/init.d/mysql start \
    && mysqltmppwd=`cat /root/.mysql_secret | cut -b 87-102` \
    && mysqladmin -u root -p${mysqltmppwd} password "admin123!@#QWE" \
    && mysql -uroot -padmin123!@#QWE -e"flush privileges" \
    && /etc/init.d/mysql stop \
    && rm -rf libaio-0.3.109-13.el7.x86_64.rpm \
    && rm -rf MySQL-client-5.6.29-1.rhel5.x86_64.rpm \
    && rm -rf MySQL-devel-5.6.29-1.rhel5.x86_64.rpm \
    && rm -rf MySQL-server-5.6.29-1.rhel5.x86_64.rpm \
    && rm -rf /var/cache/yum/* \
    && sed -i -e "10a datadir = /data/mysql" /usr/my.cnf
# 安装 nginx
RUN \
    yum -y install gcc-c++ zlib zlib-devel openssl openssl--devel pcre pcre-devel \
    && cd /usr/local \
    && tar -zxv -f nginx-1.15.5.tar.gz \
    && rm -rf nginx-1.15.5.tar.gz \
    && cd nginx-1.15.5 \
    && ./configure --with-http_stub_status_module \
    && make && make install \
    && cd .. \
    && rm -rf nginx-1.15.5 \
 #   && cp ckkxy.kz38.cn_20180615.tar.gz /usr/local/nginx/html \
 #   && cd /usr/local/nginx/html \
 #   && tar -zxvf ckkxy.kz38.cn_20180615.tar.gz \
 #   && rm -rf ckkxy.kz38.cn_20180615.tar.gz \
 #   && cp -rf /usr/local/nginx.conf /usr/local/nginx/conf \
 #   && cd /usr/local \
 #   && rm -rf nginx.conf \
    && rm -rf /var/cache/yum/*
#   && echo "daemon off" >> /usr/local/nginx/conf/nginx.conf
#安装zokeeper
    && tar -zxvf zookeeper-3.4.12.tar.gz \
    && mv zookeeper-3.4.12 zookeeper \
    && rm -rf zookeeper-3.4.12.tar.gz \
    && cp zoo.cfg /usr/local/zookeeper/conf \
RUN \
    yum -y install python-setuptools \
    && easy_install supervisor \
    && rm -rdf /var/cache/yum/*
#设置工作访问时候的WORKDIR路径,登陆落脚点
ENV MYPATH /usr/local
WORKDIR $MYPATH
# 配置java与tomcat环境变量
ENV JAVA_HOME /usr/local/jdk1.8.0_181
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV CATALINA_HOME /usr/local/apache-tomcat-8.5.34
ENV CATALINA_BASE /usr/local/apache-tomcat-8.5.34
ENV ZOOKEEPER_INSTALL=/usr/local/zookeeper
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin:ZOOKEEPER_INSTALL/bin

EXPOSE 22 80 3306 6379 8080 2181
#ENTRYPOINT /usr/local/apache-tomcat-8.5.34/bin/startup.sh && tail -F /usr/local/apache-tomcat-8.5.34/bin/logs/catalina.out
CMD /usr/bin/supervisord -c /etc/supervisord.conf && /usr/local/zookeeper-3.4.12/bin/zkServer.sh
#CMD /usr/sbin/init

   

5.构建镜像
6.运行容器

docker run --name web -d -p 12352:22 -d -p 80:80 -d -p 3306:3306 -d -p 12565:6379 -d -p 8080:8080 -d -p 13252:2181 -v /data/mysql:/data/mysql app:web

7.将在宿主机将data/nginx/conf目录下nginx.conf文件配置好。并且将项目文件放在/data/nginx/html目录下
8.数据库恢复数据需要进入运行起来的容器里,然后使用mysql -uroot -p登陆数据库

你可能感兴趣的:(docker)