由于官方php:7.2.2-fpm-alpine3.7 镜像不含composer,而单独做一个composer镜像又会依赖php镜像,所以应该在php镜像中添加composer.Dockerfile如下:
FROM php:7.2.2-fpm-alpine3.7 LABEL maintainer="php-composer Docker Maintainers <ikodota@gmail.com>" RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && \ php composer-setup.php && \ php -r "unlink('composer-setup.php');" && \ mv composer.phar /usr/local/bin/composer && \ composer self-update生成镜像
docker build -t bx-php:7.2.2-fpm-alpine3.7 准备配置文件:我的本地配置文件为 /data/server/conf/nginx/conf.d/member.conf
server { listen 80; server_name localhost; location / { root /app/public; index index.php index.html index.htm; try_files $uri $uri/ /index.php?$query_string; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ \.php$ { fastcgi_pass phpfpm:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /app/public/$fastcgi_script_name; include fastcgi_params; } } 运行docker 运行一个本地数据卷 docker run --name vc_member \ -v /data/wwwroot/retail/member/src:/app \ -v /data/server/conf/nginx/conf.d:/etc/nginx/conf.d \ alpine:latest 执行php-fpm docker run --name phpfpm -d \ --volumes-from vc_member \ bx-php:7.2.2-fpm-alpine3.7需要进入phpfpm容器,修改一些配置和文件权限,以及执行composer install /composer update等。
注意:
1.执行composer install 时,可能会出现“root用户不能使用的情况”,需要执行:composer install --no-plugins --no-scripts
2.【非常重要】进入phpfpm容器:docker exec -it phpfpm sh 然后修改“ listen = 127.0.0.1:9000” 为“listen = 9000” 否则连不上php
3.允许nginx用户访问:chown -R www-data:www-data /app
4.赋予storage目录写权限:chmod -R 755 /app/storage
这样直接输入网址就可以打开了。
Linux公社的RSS地址:https://www.linuxidc.com/rssFeed.aspx