In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
1 background introduction
In order to facilitate developers to image and encapsulate their application code, they need to provide a basic middleware image to encapsulate the application image directly on it, and then package the image according to the image packaging process on the docker compiler server, and complete all operations in a pipelined way.
Today, we will show you how to package the traditional nginx+php-fpm composite middleware software into a middleware image on docker, and then let the developer deploy its php application code to the middleware container to run.
2 Image encapsulation process
Basic image: before building a middleware image, you need to prepare a clean centos7 image to facilitate the installation of middleware such as nginx and php-fpm on the basic image.
Build middleware image: build the middleware image in advance before building the application image. However, the middleware image is based on the centos basic image to install nginx and php-fpm middleware software, optimize the configuration of middleware performance parameters, define the middleware runtime environment startup script, and finally encapsulate it into a middleware image by command.
Build an application image: take the middleware image as the basic image, write a dockerfile script to release the php code and update the nginx configuration, and finally package it into an application image by command.
Launch the application container: use the docker run command to start the application image.
3 Image encapsulation process
3.1 Environmental preparation
U image list
Image name
Mirror description
Mirror source
Centos:latest
Centos7 operating system image
Public network download
Nginx-phpfpm70:v1.0
Nginx and php middleware images are installed
Offline construction
Acitivty_admin:v1.0
Generate a new application image based on the deployment of applications on the middleware image
Offline construction
U compilation environment
1. Prepare a linux host with kernel version 3.10 or above.
2. Docker 1.13.1 software needs to be installed on the host.
3. The host needs to be able to access the external network to facilitate the download of public network images and software packages.
3.2 download centos basic image
Next, use the docker search centos command to view the public network image directly on the compilation host. Download the centos image with the most stars, then download it directly with docker pull centos, and finally download the image locally.
3.3 build a middleware image
We have downloaded the centos7 image file earlier, and now we can build the middleware image to install nginx and php-fpm software directly on the centos-based image, and finally generate a new middleware image through the docker command.
Here is a prepared dockerfile script for building an image of the middleware:
# A clean centos image
FROM centos: latest
# Image creator
MAINTAINER jaymarco@shsnc.com
# configure the yum source of php in the centos image, and then install php-related dependency packages, php-fpm software, and expansion packages corresponding to php
RUN rpm-ivh http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm & & rpm-ivh http://rpms.remirepo.net/enterprise/remi-release-7.rpm & &
Yum install-y php70-php-gd.x86_64 php70-php-mcrypt.x86_64 php70-php-fpm.x86_64 php70-php-pecl-redis.x86_64 python-setuptools\
Php70-php-mbstring.x86_64 php70-php-snmp.x86_64 php70-php-pecl-zip.x86_64\
Php70-php-mysqlnd.x86_64 php70-php-pecl-mysql.x86_64 gcc gcc-c++ automake libtool make cmake openssl openssl-devel pcre-devel & &\
Yum clean all
# install nginx software in centos image
RUN rpm-ivh http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.10.3-1.el7.ngx.x86_64.rpm
# optimized configuration of php performance parameters
RUN sed-e's catch_workers_output/s/ 127.0.0.1 error_log/d' 9000 etc/opt/remi/php70/php-fpm.d/www.conf 9000 etc/opt/remi/php70/php-fpm.d/www.conf'- e'/ error_log/d'-e'/ catch_workers_output/s/ ^; / /-e'/ error_log/d'-I / etc/opt/remi/php70/php-fpm.d/www.conf & &\
Sed-e 's/daemonize = yes/daemonize = no/'-I / etc/opt/remi/php70/php-fpm.conf
# configure the image time zone file to facilitate the time zone to be the same as that of the local host after the image is launched into a container
RUN / bin/cp / usr/share/zoneinfo/Asia/Shanghai / etc/localtime & &\
Echo 'Asia/Shanghai' > / etc/timezone
# install supervisor background process management tool to facilitate the container to start multiple processes for background monitoring and management.
# Install supervisor
RUN easy_install supervisor & &\
Mkdir-p / var/log/supervisor & &\
Mkdir-p / var/run/sshd & &\
Mkdir-p / var/run/supervisord
# COPY the locally modified supervisord configuration file to the image
ADD supervisord.conf / etc/supervisord.conf
# transfer the written script from the local COPY to the image
ADD startserv.sh / startserv.sh
RUN chmod + x / startserv.sh
# Mapping the port 809000in the container to a port in the host machine
EXPOSE 80 9000
# start nginx and php services when the container starts
CMD ["/ startserv.sh"]
The configuration file supervisord.conf. The red section below belongs to the service startup configuration.
[unix_http_server]
File=/tmp/supervisor.sock; (the path to the socket file)
[supervisord]
Logfile=/tmp/supervisord.log; (main logfile; default $CWD/supervisord.log)
Logfile_maxbytes=50MB; (max main logfile bytes b4 rotation;default 50MB)
Logfile_backups=10; (num of main logfile rotation backups;default 10)
Loglevel=info; (loglevel; default info; others: debug,warn,trace)
Pidfile=/tmp/supervisord.pid; (supervisord pidfile;default supervisord.pid)
Nodaemon=true; (start in foreground if true;default false)
Minfds=1024; (min. Avail startup file descriptors;default 1024)
Minprocs=200; (min. Avail process descriptors;default 200)
User=root
; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[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:php-fpm]
Command=/opt/remi/php70/root/usr/sbin/php-fpm-F
[program:nginx]
Command=/usr/sbin/nginx-c / etc/nginx/nginx.conf
Service startup script startserv.sh
#! / bin/sh
/ usr/bin/supervisord-n-c / etc/supervisord.conf
Once the dockerfile script and configuration file are ready, you can directly use the docker build command to build a new middleware image. Finally, a nginx-phpfpm:v1.0 image is generated locally.
Build commands:
Docker build-t nginx-phpfpm:v1.0.
Build process:
3.4 build an application image
Deploying an application image requires two things: one is the php application code, and the other is the nginx configuration file. And package these two things into the middleware image file, and finally build a new application image.
Nginx configuration parameters
Server {
Listen 8080
Server_name 127.0.0.1
Large_client_header_buffers 4 16k
Client_max_body_size 300m
Client_body_buffer_size 128k
Proxy_connect_timeout 600
Proxy_read_timeout 600
Proxy_send_timeout 600
Proxy_buffer_size 64k
Proxy_buffers 32 32k
Proxy_busy_buffers_size 64k
Proxy_temp_file_write_size 64k
Location / {
Root / var/www/cecrm_acitivtycenter
Index index.php
Try_files $uri $uri/ / index.php?$uri&$args
}
Location ^. +. Php {
Include fastcgi_params
Root / var/www/cecrm_acitivtycenter
Fastcgi_pass 127.0.0.1:9000
Fastcgi_index index.php
Fastcgi_split_path_info ^ ((? U). + .php) (/. +) $
Fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name
Fastcgi_param PATH_INFO $fastcgi_path_info
Fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info
Fastcgi_intercept_errors on
Fastcgi_connect_timeout 600
Fastcgi_send_timeout 1800
Fastcgi_read_timeout 6000
Fastcgi_buffer_size 128k
Fastcgi_buffers 4 256k
Fastcgi_busy_buffers_size 256k
Fastcgi_temp_file_write_size 256k
}
}
Php application build dockerfile script
# referencing the middleware image as the basic image of the application
FROM nginx-phpfpm70:v1.0
MAINTAINER jaymarco@shsnc.com
# release php program code
ADD admin / var/www/cecrm_acitivtycenter/admin
# Optimization of nginx performance parameters
ADD admindocker.conf / etc/nginx/conf.d/admindocker.conf
Once the dockerfile script and configuration file are ready, you can directly use the docker build command to build a new application image. Finally, an acitivty_admin:v1.0 image is generated locally.
Build commands:
Docker build-t acitivty_admin:v1.0.
Build process:
We can see that the application image has been built successfully.
3.5 Container startup and verification
Start the application container
Docker run-itd-- name acitivty_admin-p 8090 name acitivty_admin 8090 acitivty_admin:v1.0
Check the processes started in the container and find that the nginx and php-fpm processes have been started successfully
Finally, let's verify that the released application can be accessed normally.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.