溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Laravel 的 Docker 開發(fā)環(huán)境-基于centos系統(tǒng)

發(fā)布時(shí)間:2020-07-13 21:45:05 來源:網(wǎng)絡(luò) 閱讀:899 作者:hanye韓也 欄目:系統(tǒng)運(yùn)維

1 規(guī)劃

軟件:PHP 7.2、Nginx、MySQL、Composer、NPM AND  Yarn 等等;
易于擴(kuò)展使用,如隨時(shí)可以切換 PHP 版本,或者 Apache 和 Nginx 切換使用。
規(guī)劃:  先在centos鏡像安裝php-fpm和laravel的需要依賴包,使用supervisord監(jiān)控php-fpm的啟動(dòng),然后通過掛載項(xiàng)目的目錄到容器之內(nèi)   執(zhí)行腳本構(gòu)建項(xiàng)目。實(shí)現(xiàn)項(xiàng)目發(fā)布和更新迭代。
此處我僅僅處理了lavravel的php和依賴環(huán)境,并沒有處理nginx和mysql的環(huán)境,后期會(huì)出關(guān)于其他依賴的環(huán)境的操作。

Laravel 的 Docker 開發(fā)環(huán)境-基于centos系統(tǒng)

2 部署需要的安裝包

php-fpm 7.2
我這里懶省事直接在容器里面安裝處理了(開啟模塊: opcache imagick fileinfo redis swoole  )
      wget -c http://mirrors.linuxeye.com/oneinstack-full.tar.gz && tar xzf oneinstack-full.tar.gz && ./oneinstack/install.sh --php_option 7 --phpcache_option 1 --php_extensions zendguardloader,ioncube,imagick,fileinfo,redis,swoole
node
我這里選擇  node-v10.10.0-linux-x64.tar.gz
    wget https://nodejs.org/download/release/v10.10.0/node-v10.10.0-linux-x64.tar.gz
tar xf node-v10.10.0-linux-x64.tar.gz
    mv node-v10.10.0 /usr/local/node
yarn
wget install -y https://github.com/yarnpkg/yarn/releases/download/v1.13.0/yarn-1.13.0-1.noarch.rpm
yum install -y yarn-1.13.0-1.noarch.rpm
安裝 nodejs 8
 curl -sL https://rpm.nodesource.com/setup_8.x | bash -
安裝compose
cd /usr/local/bin
curl -s https://getcomposer.org/installer | php
chmod a+x composer.phar     
composer.phar self-update      
mv composer.phar composer   
supervisor安裝
yum install -y epel-release 
yum install -y supervisor

配置環(huán)境啟動(dòng)腳本和supervisor啟動(dòng)配置

[root@58b32f9d29d0 /]# cat /root/startphp-fpm.sh 
 #!/bin/bash
 supervisord  -n -c /etc/supervisord.conf
 [root@58b32f9d29d0 /]# cat /etc/supervisord.conf |grep -vE  "^;|^$"
    [unix_http_server]
    file=/var/run/supervisor/supervisor.sock   ; (the path to the socket file)
    [supervisord]
    logfile=/var/log/supervisor/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=/var/run/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)
    [rpcinterface:supervisor]
    supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
    [supervisorctl]
    serverurl=unix:///var/run/supervisor/supervisor.sock ; use a unix:// URL  for a unix socket
    [program:php-fpm]
    process_name=%(program_name)s_%(process_num)02d
    command=/usr/local/php/sbin/php-fpm --fpm-config /usr/local/php/etc/php-fpm.conf
    #stdout_logfile=/data/wwwlogs/php-fpm-sup.log
    autostart=true
    autorestart=true
    startretries=5
    exitcodes=0,2,70
    stopsignal=QUIT
    stopwaitsecs=2
    [include]
    files = supervisord.d/*.ini
處理完畢 刪除安裝包和清理yum緩存 打包為鏡像
 rm -fr  oneinstack-full.tar.gz oneinstack    yarn-1.13.0-1.noarch.rpm node-v10.10.0-linux-x64.tar.gz
     yum cleal all
打包為鏡像laravel 環(huán)境
     docker commit -a "laravel 環(huán)境初始化"  58b32f9d29d0  hanye131/fangxinerp:supvisor_php-fpm72
啟動(dòng)鏡像
 docker run -itd --name=test1 -v /data/startphp-fpm.sh:/root/startphp-fpm.sh -v /data/supervisord.conf:/etc/supervisord.conf hanye131/fangxinerp:supvisor_php-fpm72
模擬項(xiàng)目啟動(dòng)
docker run -itd --name=test1 -v /data/startphp-fpm.sh:/root/startphp-fpm.sh -v /data/supervisord.conf:/etc/supervisord.conf  -v /var/www/html:/var/www/html  -v /root/laravel-install.sh:/root/laravel-install.sh: hanye131/fangxinerp:supvisor_php-fpm72
/root/laravel-install.sh
#!/bin/bash
     export PATH=/usr/local/php/bin:/usr/local/php/sbin:/usr/local/node/bin:$PATH
     cd /var/www/html
     composer install
     yarn install
     php artisan migrate --force
     php artisan queue:restart
     npm run dev

Dockerfile

FROM centos:latest
MAINTAINER hz7726@163.com
ENV PATH /usr/local/php/bin:/usr/local/php/sbin:/usr/local/node/bin:$PATH
RUN yum install -y wget \
   && mkdir -p /data/docker \
   && cd /data/docker \
   && wget -c http://mirrors.linuxeye.com/oneinstack-full.tar.gz && tar xzf oneinstack-full.tar.gz && ./oneinstack/install.sh --php_option 7 --phpcache_option 1 --php_extensions zendguardloader,imagick,fileinfo,redis,swoole \
   && wget https://nodejs.org/download/release/v10.10.0/node-v10.10.0-linux-x64.tar.gz \
   && tar xf node-v10.10.0-linux-x64.tar.gz \
   && mv node-v10.10.0-linux-x64 /usr/local/node \
   && curl -sL https://rpm.nodesource.com/setup_8.x | bash - \
   && wget  https://github.com/yarnpkg/yarn/releases/download/v1.13.0/yarn-1.13.0-1.noarch.rpm  \
   && yum install -y yarn-1.13.0-1.noarch.rpm  
COPY php_etc.tar.gz /usr/local/php/etc/
RUN  cd /usr/local/php/etc/ \
    && tar xf php_etc.tar.gz
#COPY /data/php-fpm /etc/init.d/php-fpm
#COPY /data/composer /usr/local/bin/composer
#RUN chmod +x /etc/init.d/php-fpm \
#&& chkconfig --add php-fpm \
&& sed -i 's@disable_functions@;disable_functions@' /usr/local/php/etc/php.ini\
&& rm -fr /data/docker && yum cleal all
CMD ['/usr/local/php/sbin/php-fpm','--fpm-config','/usr/local/php/etc/php-fpm.conf']

https://gitee.com/hanyehell/DockerInstall/tree/master/docker-Laravel-php-fpm

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI