1、Docker 部署,在 Jenkins 上构建镜像时,报错:composer install returned a non-zero code: 255,如图1
Step 7 : RUN chown -R nginx:nginx /mcloud/www/ && rm -rf /etc/nginx/conf.d/status.conf && composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ && cd /mcloud/www/pcs-api && composer install ---> Running in a73905f2bdbc [91mDo not run Composer as root/super user! See https://getcomposer.org/root for details [0mThe command '/bin/sh -c chown -R nginx:nginx /mcloud/www/ && rm -rf /etc/nginx/conf.d/status.conf && composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ && cd /mcloud/www/pcs-api && composer install' returned a non-zero code: 255 Build step 'Docker Build and Publish' marked build as failure Finished: FAILURE
2、Dockerfile 执行命令失败的代码如下
FROM registry-vpc.cn-beijing.aliyuncs.com/cmc/centos-nginx112-php72:0.1.12 MAINTAINER wangqiang@chinamcloud.com RUN sed -i 's/open_basedir = .//://mcloud://tmp://data://webtv/;open_basedir = .//://mcloud://tmp://data://webtv://usr//local//php/g' /usr/local/php/etc/php.ini && / sed -i 's/allow_url_fopen = Off/allow_url_fopen = On/g' /usr/local/php/etc/php.ini && / sed -i 's/disable_functions = exec,system,passthru,shell_exec,escapeshellarg,escapeshellcmd,proc_close,proc_open,dl,popen,show/disable_functions = system,shell_exec,escapeshellarg,escapeshellcmd,dl,popen,show/g' /usr/local/php/etc/php.ini COPY code /mcloud/www/pcs-api COPY code/build/c_files/ / RUN chown -R nginx:nginx /mcloud/www/ && / rm -rf /etc/nginx/conf.d/status.conf && / chmod +x /usr/local/bin/composer && / composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ && / cd /mcloud/www/pcs-api && / composer install
3、编辑 Dockerfile,构建成功,可见失败的原因在于:composer install
RUN chown -R nginx:nginx /mcloud/www/ && / rm -rf /etc/nginx/conf.d/status.conf && / chmod +x /usr/local/bin/composer && / composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ && / cd /mcloud/www/pcs-api
4、编辑 Dockerfile,查看 composer 的版本信息与全局配置选项的列表
RUN chown -R nginx:nginx /mcloud/www/ && / rm -rf /etc/nginx/conf.d/status.conf && / chmod +x /usr/local/bin/composer && / composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ && / cd /mcloud/www/pcs-api && / composer --version && / composer config --global --list
5、在 Jenkins 上构建镜像时,仍然报错:composer install returned a non-zero code: 255,可见,composer 相关的命令是执行不了的,不仅是 composer install,如图2
6、编辑 Dockerfile,下载 Composer 的可执行文件,局部安装
RUN chown -R nginx:nginx /mcloud/www/ && / rm -rf /etc/nginx/conf.d/status.conf && / cd /mcloud/www/pcs-api && / curl -sS https://getcomposer.org/installer | php && / php composer.phar install
7、在 Jenkins 上构建镜像时,报错:php composer.phar install returned a non-zero code: 1,如图3
RUN chown -R nginx:nginx /mcloud/www/ && rm -rf /etc/nginx/conf.d/status.conf && cd /mcloud/www/pcs-api && curl -sS https://getcomposer.org/installer | php && php composer.phar install ---> Running in 28a2ad979c18 All settings correct for using Composer Warning: is_dir(): open_basedir restriction in effect. File(/root/.composer) is not within the allowed path(s): (./:/sobey:/tmp:/data:/webtv:/var/log:/mcloud) in Standard input code on line 495 Warning: is_dir(): open_basedir restriction in effect. File(/root/.composer) is not within the allowed path(s): (./:/sobey:/tmp:/data:/webtv:/var/log:/mcloud) in Standard input code on line 685 Unable to create Composer home directory "/root/.composer": mkdir(): open_basedir restriction in effect. File(/root/.composer) is not within the allowed path(s): (./:/sobey:/tmp:/data:/webtv:/var/log:/mcloud) The command '/bin/sh -c chown -R nginx:nginx /mcloud/www/ && rm -rf /etc/nginx/conf.d/status.conf && cd /mcloud/www/pcs-api && curl -sS https://getcomposer.org/installer | php && php composer.phar install' returned a non-zero code: 1 Build step 'Docker Build and Publish' marked build as failure Finished: FAILURE
8、醒悟过来,原因在于 Dockerfile 文件,之前执行了批量替换,将 sobey 批量替换为 mcloud,决定仅替换其中的 3 处,其余 2 处的 mcloud 还原为 sobey,如图4
FROM registry-vpc.cn-beijing.aliyuncs.com/cmc/centos-nginx112-php72:0.1.12 MAINTAINER wangqiang@chinamcloud.com RUN sed -i 's/open_basedir = .//://sobey://tmp://data://webtv/;open_basedir = .//://sobey://tmp://data://webtv://usr//local//php/g' /usr/local/php/etc/php.ini && / sed -i 's/allow_url_fopen = Off/allow_url_fopen = On/g' /usr/local/php/etc/php.ini && / sed -i 's/disable_functions = exec,system,passthru,shell_exec,escapeshellarg,escapeshellcmd,proc_close,proc_open,dl,popen,show/disable_functions = system,shell_exec,escapeshellarg,escapeshellcmd,dl,popen,show/g' /usr/local/php/etc/php.ini COPY code /mcloud/www/pcs-api COPY code/build/c_files/ / RUN chown -R nginx:nginx /mcloud/www/ && / rm -rf /etc/nginx/conf.d/status.conf && / chmod +x /usr/local/bin/composer && / composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ && / cd /mcloud/www/pcs-api && / composer install
9、Docker 部署,在 Jenkins 上构建镜像成功,后续有待于基础镜像升级之后,才能够全部执行替换了的。如图5
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/181367.html