요구사항:
docker를 사용하여 nginx + tomcat 이중 프로세스를 시작하세요. 실제 애플리케이션에서는 여러 프로세스가 비교적 일반적입니다.
1: dockerfile 디렉터리 만들기
mkdir -p /docker/web
2: dockerfile 작성: /docker/web/dockerfile
from centos7 maintainer lin test@163.com copy centos-base.repo /etc/yum.repos.d/centos-base.repo copy nginx_install.sh /tmp/nginx_install.sh run 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.gz copy tomcat_install.sh /tmp/tomcat_install.sh run sh /tmp/tomcat_install.sh; \rm -rf /usr/local/src/* copy supervisor_install.sh /tmp/supervisor_install.sh copy supervisord.conf /etc/supervisord.conf copy start_tomcat.sh /usr/local/tomcat/bin/mystart.sh run 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 - base baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/rpm-gpg-key-centos-7 #released updates [updates] name=centos-$releasever - updates baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/rpm-gpg-key-centos-7 #additional packages that may be useful [extras] name=centos-$releasever - extras baseurl=http://mirrors.163.com/centos/$releasever/extras/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/rpm-gpg-key-centos-7 #additional packages that extend functionality of existing packages [centosplus] name=centos-$releasever - plus baseurl=http://mirrors.163.com/centos/$releasever/centosplus/$basearch/ gpgcheck=1 enabled=0 gpgkey=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/src wget 'http://nginx.org/download/nginx-1.12.2.tar.gz' tar -zxvf nginx-1.12.2.tar.gz cd nginx-1.12.2 ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-stream --with-stream_ssl_module make make install exit 0
3.3tomcat 설치 스크립트
[root@docker web]# cat tomcat_install.sh yum install -y wget tar cd /usr/local/src/ tar -zxvf jdk-8u162-linux-x64.tar.gz mv 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/profile echo 'path=$path:$java_home/bin' >>/etc/profile echo 'classpath=.:$java_home/lib/tools.jar:$java_home/lib/dt.jar:$classpath' >>/etc/profile source /etc/profile wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.38/bin/apache-tomcat-8.5.38.tar.gz tar -zxvf apache-tomcat-8.5.38.tar.gz mv apache-tomcat-8.5.38 /usr/local/tomcat
3.4dockerfile 파일에 포함된 구성 파일, 스크립트, 설치 패키지는 다음과 같습니다.
[root@docker web]# ll total 185384 -rw-r--r-- 1 root root 835 mar 9 01:12 centos-base.repo -rw-r--r-- 1 root root 669 mar 9 01:11 dockerfile -rw-r--r-- 1 root root 189815615 mar 9 01:15 jdk-8u162-linux-x64.tar.gz -rw-r--r-- 1 root root 340 mar 9 01:13 nginx_install.sh -rw-r--r-- 1 root root 581 mar 9 01:17 tomcat_install.sh
4: 원클릭 설치 감독자: /docker/web/supervisor_install.sh
yum -y install epel-release yum -y install python2-pip pip install supervisor
5: 감독자 구성 파일: /docker/web/supervisord.conf
[unix_http_server] file=/tmp/supervisor.sock ; the path to the socket file [supervisord] logfile=/tmp/supervisord.log ; 日志 logfile_maxbytes=50mb ; 最大50m日志 logfile_backups=10 ; 轮循日志备份10个 loglevel=info ; 日志等级记录info的 pidfile=/tmp/supervisord.pid ;pid nodaemon=true ;在前台启动 minfds=102400 ; 文件描述符限制 minprocs=2000 ; 进程数 [rpcinterface:supervisor] supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface [supervisorctl] serverurl=unix:///tmp/supervisor.sock ; use a unix:// url for a unix socket [program:nginx] command=/usr/local/nginx/sbin/nginx ; 前台启动nginx autostart=true ; 随着supervisor自动启动 startsecs=10 ; 启动10s后算正常启动 autorestart=true ; 程序退出后自动重启 startretries=3 ; 启动失败自动重试次数 stdout_logfile_maxbytes=20mb ;stdout 日志文件大小最大20mb stdout_logfile=/usr/local/nginx/logs/out.log [program:tomcat] command=sh /usr/local/tomcat/bin/mystart.sh ; 前台启动tomcat autostart=true ; 随着supervisor自动启动 startsecs=10 ; 启动10s后算正常启动 autorestart=true ; 程序退出后自动重启 startretries=3 ; 启动失败自动重试次数 stdout_logfile_maxbytes=20mb ;stdout 日志文件大小最大20mb stdout_logfile=/usr/local/tomcat/logs/catalina.out
6: tomcat 시작 스크립트/docker/web/start_tomcat .sh
#由于supervisor无法使用source,需要编写个脚本来启动 source /etc/profile /usr/local/tomcat/bin/catalina.sh run
7: 미러 빌드
cd /docker/web docker build -t shijiange_web . [root@docker web]# docker images repository tag image id created size shijiange_web latest bc06a9974252 7 seconds ago 1.33 gb
8: 컨테이너 테스트 시작
[root@docker web]# docker run -d shijiange_web /bin/bash -c 'supervisord -c /etc/supervisord.conf' 76782ab71c3b1d2f818ad76214d6336ae11a524eeb9d211f154fe4ad5226015d [root@docker web]# [root@docker web]# docker ps container id image command created status ports names 76782ab71c3b shijiange_web "container-entrypo..." 12 seconds ago up 12 seconds happy_jones
9. 테스트 확인:
[root@docker web]# docker exec -it 76782ab /bin/bash bash-4.2# ifconfig
10. 컨테이너 확인: 컬 nginx
11. 톰캣
위 내용은 감독자를 사용하여 nginx 및 tomcat 컨테이너를 관리하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!