Docker
构建PHP7.4+redis+swoole+nginx+supervisord 镜像
一: PHP安装请看:https://blog.csdn.net/SparkLee2013/article/details/109057329
最新版本:https://blog.remirepo.net/
(若出现php-fpm 无法启动的问题是无法创建php.pid, 请修改php-fpm.conf 文件,把pid生成路径调整为 = /var/run/php-fpm/php-fpm.pid)
(出现redis错误:undefined symbol: php_json_decode_ex, 在php.ini 加入redis.so 之前,加载 json.so, 或者在目录 /etc/php.d/ 新建 redis.ini文件)
二: 构建:cd到dockerfile 目录, 命令: docker build -t work:v1 .
三: 运行:docker run --name web-v4 -p 80:80 -v /home/wwwroot:/home/wwwroot -v /home/wwwlogs:/home/wwwlogs -v /home/conf.d:/etc/nginx/conf.d -v /home/shell:/home/shell -d 镜像ID
Dockerfile
FROM daocloud.io/library/centos:centos7.8.2003
MAINTAINER loveqzhi@163.com
ENV SWOOLE_VERSION 4.8.5
ENV REDIS_VERSION 5.3.5
ENV MSGPACK_VERSION 2.0.3
RUN set -x && \
## Install php7.4
yum -y install epel-release && \
yum -y install deltarpm && \
yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm && \
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm && \
yum -y install nginx && \
yum -y install redis && \
systemctl enable nginx.service && \
systemctl enable redis.service && \
yum install -y yum-utils && \
yum-config-manager --disable 'remi-php*' && \
yum-config-manager --enable remi-php74 && \
yum repolist && \
yum -y install gcc g++ gcc-c++ wget make libcurl nghttp2 libnghttp2-devel curl-devel mysql-devel && \
yum -y install php php-fpm php-cli php-common php-opcache php-pecl-zip php-pecl-mysql php-devel php-mbstring php-bcmath php-gd php-process php-mysql php-xml php-xmlrpc php-pecl-imagick && \
rm -rf /var/cache/yum/x86_64/7/updates/packages/* && \
## Mkdir & Add user
mkdir -p /data/wwwlogs && \
useradd -r -s /sbin/nologin -d /data/wwwroot -m -k no www && \
## Download software
mkdir -p /home/src && \
cd /home/src && \
curl -L http://pecl.php.net/get/swoole-$SWOOLE_VERSION.tgz | tar zxv -C /home/src && \
curl -L http://pecl.php.net/get/redis-$REDIS_VERSION.tgz | tar zxv -C /home/src && \
curl -L http://pecl.php.net/get/msgpack-$MSGPACK_VERSION.tgz | tar zxv -C /home/src && \
## Install swoole
cd /home/src/swoole-$SWOOLE_VERSION && \
/usr/bin/phpize && \
./configure --with-php-config=/usr/bin/php-config --enable-http2 --enable-openssl && \
make && \
make install && \
sed -i '$a extension=swoole.so' /etc/php.ini && \
## Install redis
cd /home/src/redis-$REDIS_VERSION && \
/usr/bin/phpize && \
./configure --with-php-config=/usr/bin/php-config && \
make && \
make install && \
sed -i '$a extension=redis.so' /etc/php.ini && \
## Install msgpack
cd /home/src/msgpack-$MSGPACK_VERSION && \
/usr/bin/phpize && \
./configure --with-php-config=/usr/bin/php-config && \
make && \
make install && \
sed -i '$a extension=msgpack.so' /etc/php.ini && \
## Install super
yum install -y supervisor && \
systemctl enable supervisord && \
mkdir -p /var/{log/supervisor,run/{sshd,supervisord}} && \
##yum remove
yum remove -y gcc g++ gcc-c++ cpp wget && \
yum clean all && \
rm -rf /tmp/* /var/cache/{yum,ldconfig} && \
mkdir /data/shell && \
chown root:root /usr/sbin/nginx && \
chmod u+s /usr/sbin/nginx && \
chown -R www:www /data/wwwroot && \
chown -R www:www /data/wwwlogs && \
#修改时区
/bin/cp -rf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#create web folder
VOLUME ["/data/wwwroot", "/data/wwwlogs", "/etc/nginx/conf.d", "/data/shell"]
# add supervisord.conf
ADD supervisord.conf /etc/
# add start sh
ADD start.sh /
RUN chmod +x /start.sh
ENTRYPOINT ["/start.sh"]
start.sh
#!/bin/bash
function getdir(){
for element in `ls $1`
do
dir_or_file=$1"/"$element
if [ -d $dir_or_file ]
then
getdir $dir_or_file
else
chmod +x $dir_or_file
$dir_or_file
fi
done
}
#shell_dir="/data/shell"
#getdir $shell_dir
/usr/bin/supervisord -n -c /etc/supervisord.conf
supervisord.conf
[unix_http_server]
file=/tmp/supervisor.sock ; (the path to the socket file)
[supervisord]
logfile=/tmp/supervisord.log ; (main log file;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 ; (log level;default info; others: debug,warn,trace)
pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=false ; (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=/usr/sbin/php-fpm -F
autostart=true
autorestart=true
priority=5
[program:nginx]
command = /usr/sbin/nginx -g 'daemon off;'
stdout_logfile=/data/wwwlogs/nginx_stdout.log
stdout_logfile_maxbytes=10MB
stderr_logfile=/data/wwwlogs/nginx_stderr.log
user = nginx
stderr_logfile_maxbytes=10MB
autostart=true
autorestart=true
[program:redis]
command = /usr/bin/redis-server
autostart=true
autorestart=true