需求:
使用docker来启动nginx + tomcat 双进程,实际应用中,多进程还是比较常见的。
1: 创建dockerfile目录
mkdir -p /docker/web
2: 编写dockerfile: /docker/web/Dockerfile
FROM centos7MAINTAINER lin test@163.comCOPY CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repoCOPY nginx_install.sh /tmp/nginx_install.shRUN sh /tmp/nginx_install.sh; /rm -rf /usr/local/src/*RUN sed -i -e '/worker_processes/a daemon off;' /usr/local/nginx/conf/nginx.conf; COPY jdk-8u162-linux-x64.tar.gz /usr/local/src/jdk-8u162-linux-x64.tar.gzCOPY tomcat_install.sh /tmp/tomcat_install.shRUN sh /tmp/tomcat_install.sh; /rm -rf /usr/local/src/* COPY supervisor_install.sh /tmp/supervisor_install.shCOPY supervisord.conf /etc/supervisord.confCOPY start_tomcat.sh /usr/local/tomcat/bin/mystart.shRUN sh /tmp/supervisor_install.sh; /rm -rf /tmp/*.sh
3: dockerfile集成的配置文件及安装文件
3.1 默认源下载较慢,更换yum源,以下CentOS-Base.repo配置文件拷贝到容器里更换
COPY CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo[root@docker web]# cat CentOS-Base.repo [base]name=CentOS-$releasever - Basebaseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 #released updates[updates]name=CentOS-$releasever - Updatesbaseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 #additional packages that may be useful[extras]name=CentOS-$releasever - Extrasbaseurl=http://mirrors.163.com/centos/$releasever/extras/$basearch/gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 #additional packages that extend functionality of existing packages[centosplus]name=CentOS-$releasever - Plusbaseurl=http://mirrors.163.com/centos/$releasever/centosplus/$basearch/gpgcheck=1enabled=0gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
3.2nginx安装脚本
[root@docker web]# cat nginx_install.sh yum install -y wget tar gcc gcc-c++ make pcre pcre-devel zlib zlib-devel openssl openssl-devel cd /usr/local/srcwget 'http://nginx.org/download/nginx-1.12.2.tar.gz'tar -zxvf nginx-1.12.2.tar.gzcd nginx-1.12.2./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-stream --with-stream_ssl_modulemakemake installexit 0
3.3tomcat安装脚本
[root@docker web]# cat tomcat_install.sh yum install -y wget tarcd /usr/local/src/tar -zxvf jdk-8u162-linux-x64.tar.gzmv jdk1.8.0_162 /usr/local/#/usr/local/jdk1.8.0_162/bin/java -version #配置java环境变量echo 'JAVA_HOME=/usr/local/jdk1.8.0_162/' >>/etc/profileecho 'PATH=$PATH:$JAVA_HOME/bin' >>/etc/profileecho 'CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:$CLASSPATH' >>/etc/profilesource /etc/profile wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.38/bin/apache-tomcat-8.5.38.tar.gztar -zxvf apache-tomcat-8.5.38.tar.gzmv apache-tomcat-8.5.38 /usr/local/tomcat
新闻热点
疑难解答