1、启动纯静ubuntu容器
sudo docker run -it –name ubuntu-phpfpm7.3-0.1 registry.cn-beijing.aliyuncs.com/jd100-pub/ubuntu:20190304 /bin/bash
> 759668f30865
2、修改源
echo ‘deb bionic main restricted
deb bionic-updates main restricted
deb bionic universe
deb-src bionic universe
deb bionic-updates universe
deb-src bionic-updates universe
deb bionic multiverse
deb bionic-updates multiverse
deb bionic-backports main restricted universe multiverse
deb bionic-security main restricted
deb bionic-security universe
deb-src bionic-security universe
deb bionic-security multiverse
‘ >/etc/apt/sources.list;
apt-get update
apt-get install software-properties-common
add-apt-repository ppa:ondrej/php
add-apt-repository ppa:ondrej/nginx
apt-get update
apt-get install -y php7.3-fpm (要求选择时区的时候选择 欧洲 (8Europe)/ 伦敦(27. London))
apt-get install -y nginx (nginx version: nginx/1.14.2)
(相关信息:php-pear
Creating config file /etc/php/7.3/fpm/php.ini with new version
)
========================
apt-get –purge remove php-common
apt-get install php-common php-mysql php-redis php-mbstring php-fpm php-gd php-tokenizer php-curl php-cli openssl
lume需要的扩展:
Mcrypt PHP Extension mcrypt (7.3版本使用openssl替代mcrypt )
OpenSSL PHP Extension
查找安装php常用的扩展,容器:36cabe4eea3a
========================
查看php-fpm:
whereis php-fpm
/usr/sbin/php-fpm7.3 (启动fpm,启动时报ERROR: unable to bind listening socket for address ‘/run/php/php7.3-fpm.sock’: No such file or directory, 此时先mkdir /run/php即可)
启动nginx
优化nginx配置
events {
use epoll;
worker_connections 51200;
multi_accept on;
}
gzip on;
gzip_disable “msie6”;
gzip_vary on;
gzip_proxied any;
# gzip_comp_level 6;
gzip_min_length 1k;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
优化php-fpm
cat /etc/php/7.3/fpm/php-fpm.conf
新建开机启动脚本(需要开机启动的加入到里面)
/opt/autorun/reboot.sh
(新建步骤:
1、在宿主机中新建/opt/autorun/reboot.sh
#!/bin/bash
/usr/sbin/php-fpm7.3
nginx
2、容器中新建目录
mkdir /opt/autorun/
3、sudo docker cp reboot.sh 91b004bc998c:/opt/autorun/reboot.sh
3d87c9b09b8d-镜像id
chmod 777 /opt/autorun/reboot.sh
将容器打基础镜像
1、sudo docker commit 759668f30865 ubuntu_nginx1.42_phpfpm7.3:0.2
2、使用Dockerfile测试试用(course-service目录下)
修改Dockerfile使用指定镜像
sudo docker build -t test-php7.3:1.0 .
3、启动测试
sudo docker run -d –name test-php-v1.0 -p 9003:80 test-php7.3:1.0
直接访问宿主机:
(测试过程命令)
sudo docker cp index.php 3943df1e1fa7:/var/www/html
sudo docker cp default 3943df1e1fa7:/etc/nginx/sites-enabled/default
sudo docker cp php.ini 3943df1e1fa7:/etc/php/7.3/fpm/php.ini
nginx use www-data
php-fpm
chown -R www-data /var/www/html/
chgrp -R www-data /var/www/html/
sudo docker run -it –name test-php-v1.2 -p 9003:80 ubuntu_nginx1.42_phpfpm7.3:0.2
sudo docker build -t ubuntu-php7.3:0.14 .
通过添加reboot.sh做启动操作
FROM ubuntu-php7.3:0.13
CMD [“sh”, “/opt/autorun/reboot.sh”]
遇到的问题:
配置apache2.4修改documentRoot出现You don’t have permission to access / on this server
没有配置/etc/apache2/apache2.conf中的目录
docker启动后避免自动退出:
tail -f /dev/null
相关文件
reboot.sh
#!/bin/bash
/usr/sbin/php-fpm7.3
nginx
tail -f /dev/null
或者:
#!/bin/bash
/usr/sbin/php-fpm7.3
nginx -g “daemon off;”
apt-cache search php
注意大坑:fpm与nginx通讯使用9000端口形式,不要使用socket形式,出错率很高