docker commit方式制作nginx+php-fpm镜像(源码编译)nginx-1.18.0.tar.gz + php-7.4.15.tar.gz

# docker run -it --name=c1 centos:7.9.2009 /bin/bash
[root@7206eb08a3a0 ~]# yum -y install vim iproute
脚本内容
[root@7206eb08a3a0 ~]# cat 123.sh
yum -y install epel-release 
yum -y install gcc gcc-c++ make wget pcre-devel zlib-devel openssl-devel libxml2-devel sqlite-devel libcurl-devel libpng-devel freetype-devel openssl-devel curl-devel oniguruma-devel

useradd -r -s /sbin/nologin www

wget https://nginx.org/download/nginx-1.18.0.tar.gz
wget https://www.php.net/distributions/php-7.4.15.tar.gz

tar -xf nginx-1.18.0.tar.gz
tar -xf php-7.4.15.tar.gz

cd /root/nginx-1.18.0
./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module &&  make -j2 && make install

#启动nginx,ps -ef |grep nginx
/usr/local/nginx/sbin/nginx

cd /root/php-7.4.15
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-zlib --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-ftp --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts && make -j 2 && make install

cp /root/php-7.4.15/php.ini-development /usr/local/php/etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

echo 'export PATH=$PATH:/usr/local/php/bin' >> /etc/profile
source /etc/profile

#启动php-fpm,ps -ef |grep php-fpm
/usr/local/php/sbin/php-fpm

#Nginx+php-fpm配置

mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak

cat > /usr/local/nginx/conf/nginx.conf <<"EOF"
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        root   html;
        location / {
            index  index.html index.htm;
        }
        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
            }
            error_page   500 502 503 504  /50x.html;
        location = /50x.html {
        }
    }
}
EOF

/usr/local/nginx/sbin/nginx -s reload

cat > /usr/local/nginx/html/demo.php <<EOF
<?php
	phpinfo();
?>
EOF

#设置启动容器自启动

echo "/usr/local/nginx/sbin/nginx" >>/etc/rc.local
echo "/usr/local/php/sbin/php-fpm">>/etc/rc.local
echo "/bin/bash" >>/etc/rc.local
chmod +x /etc/rc.d/rc.local

[root@7206eb08a3a0 ~]# sh 123.sh
[root@7206eb08a3a0 ~]# curl http://localhost
[root@7206eb08a3a0 ~]# curl http://localhost/demo.php
[root@k8s-master ~]# docker commit c1 my_centos792009_nginx_php-fpm:v1

测试镜像
[root@k8s-master ~]# docker run -itd -p 80:80 --restart=always -v /data/nginx/html:/usr/local/nginx/html my_centos792009_nginx_php-fpm:v1 /etc/rc.local
[root@k8s-master ~]# echo "123" > /data/nginx/html/index.html
[root@k8s-master ~]# curl http://192.168.1.201
[root@k8s-master ~]# echo "321" > /data/nginx/html/demo.php
[root@k8s-master ~]# curl http://192.168.1.201/demo.php
cat > /data/nginx/html/demo.php <<EOF
<?php
	phpinfo();
?>
EOF

[root@k8s-master ~]# curl http://192.168.1.201/demo.php
游览器(google访问)
http://192.168.1.201/demo.php
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值