need: Use docker to start nginx + tomcat dual process. In actual applications, multiple processes are quite common. 1: Create a Dockerfile directory mkdir -p /docker/web 2: Write Dockerfile: /docker/web/Dockerfile FROM centos7 MAINTAINER lin [email protected] 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 integrated configuration files and installation files 3.1 The default source download is slow, change the yum source, copy the following CentOS-Base.repo configuration file to the container and change it 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 installation script [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 installation script [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 #Configure java environment variables 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.4 The configuration files, scripts, and installation packages involved in the dockerfile file are as follows [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: One-click installation of supervisor: /docker/web/supervisor_install.sh yum -y install epel-release yum -y install python2-pip pip install supervisor 5: supervisor configuration file: /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; maximum 50MB logfile_backups=10; 10 log backups in rotationloglevel=info; log level record infopidfile=/tmp/supervisord.pid;pid nodaemon=true ; Start in foreground minfds=102400 ; File descriptor limit minprocs=2000 ; Number of processes [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 ; Start nginx in the foreground autostart=true; automatically starts with supervisorstartsecs=10; a normal startup is considered after 10 seconds of startupautorestart=true; automatically restarts after the program exitsstartretries=3; the number of automatic retries when startup failsstdout_logfile_maxbytes=20MB; the maximum size of stdout log file is 20Mb stdout_logfile=/usr/local/nginx/logs/out.log [program:tomcat] command=sh /usr/local/tomcat/bin/mystart.sh ; Start tomcat in the foreground autostart=true; automatically starts with supervisorstartsecs=10; a normal startup is considered after 10 seconds of startupautorestart=true; automatically restarts after the program exitsstartretries=3; the number of automatic retries when startup failsstdout_logfile_maxbytes=20MB; the maximum size of stdout log file is 20Mb stdout_logfile=/usr/local/tomcat/logs/catalina.out 6: tomcat startup script /docker/web/start_tomcat.sh #Since supervisor cannot use source, you need to write a script to start source /etc/profile /usr/local/tomcat/bin/catalina.sh run 7: Build the image 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: Start container test [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. Test verification: [root@docker web]# docker exec -it 76782ab /bin/bash bash-4.2# ifconfig 10. Container verification: curl nginx 11. Container verification: curl tomcat The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: js implements the algorithm for specifying the order and amount of red envelopes
>>: Examples of optimization techniques for slow query efficiency in MySQL IN statements
1. Why write this article? You must have read a l...
Key Takeaways: 1. Mastering CSS3 3D animation 2. ...
Table of contents Business scenario: Effect demon...
Table of contents Effect display Code Link Key Co...
After the changes: innodb_buffer_pool_size=576M -...
Usually the pictures uploaded by users need to be...
1. Complex SQL queries 1.1. Single table query (1...
1. Description In MySQL, when we need to get the ...
Common Convention Tags Self-closing tags, no need...
After going through a lot of hardships, I searched...
1. Download the installation package from the off...
When I configured mysql, I set the default storag...
Preface The concept of dark mode originated from ...
1. Packaging Vue project Enter the following name...
Table of contents 1. Open the project directory o...