重点记录下:
- php开发环境,和laravel开发环境的搭建的区别,别再入坑
- 开发环境不用任何其它集成环境(各种php集成环境都不需要),只需要装了docker,docker-compose即可
- php-fpm: FastCGI进程管理器
编写Dockerfile
从dockerhub上找的镜像
FROM arsaga/laravel-alpine:7.3-zip
RUN pecl install igbinary && docker-php-ext-enable igbinary && \
pecl install redis && docker-php-ext-enable redis &&\
pecl install mongodb && docker-php-ext-enable mongodb && \
pecl install msgpack && docker-php-ext-enable msgpack
docker build
docker build ./env/ -t php_base:7.3
编写docker-compose.yml
version: '3.1'
services:
api:
command: php -S 0.0.0.0:80 -t /www/project/public/
image: php_base:7.3
ports:
- 18002:80/tcp
volumes:
- /home/java/zd_php/php_docker/www/xc_api:/www/xc_api
运行容器
docker-compose up -d
运行项目命令: (PS: 不在项目根目录也可以运行)
php -S 0.0.0.0:80 -t /www/project/public/
或者
php /www/project/artisan serve --port=80 --host=0.0.0.0
虽然内置了composer,但是在容器运行.会出现composer update 会报 Allowed memory size of 1610612736 bytes exhausted
还得研究下php-fpm的相关配置
php-fpm配置文件详解
基础容器
FROM php:7.2-fpm-alpine
MAINTAINER arsaga
RUN apk --update add zlib-dev \
libmcrypt-dev \
libpng-dev \
&& rm -rf /var/cache/apk/* && \
docker-php-ext-install mbstring && \
docker-php-ext-install pdo_mysql && \
docker-php-ext-install opcache && \
docker-php-ext-install zip && \
docker-php-ext-install gd && \
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer && \
composer global require hirak/prestissimo && \
apk add --update --no-cache autoconf g++ imagemagick-dev libtool make pcre-dev \
&& pecl install imagick \
&& docker-php-ext-enable imagick
容器内执行supervisord
- 更换alpinelinux为国内镜像地址
- 更换supervisord 默认配置.ini后缀配置文件
- 无法创建用户问题还未解决
- 生成容器 docker build . -t php_base_supervisor1:7.3 测试
编写dockerfile
FROM php_base:7.3
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk add supervisor
RUN sed -i 's/*.ini/*.conf/g' /etc/supervisord.conf
#RUN useradd user1 -m -d /home/user1
#RUN chmod 775 /home/user1
ENTRYPOINT ["/usr/bin/supervisord", "-n", "-c", "/etc/supervisord.conf"]
编写docker-compose.yml
version: "3"
services:
app:
build: queue/app
volumes:
- /queue/supervisord:/etc/supervisor.d
- /queue/log:/var/log
- /api:/data/www/api
docker容器内无法使用宿主机软链接的文件或目录,可以自行配置数据卷进行映射文件或目录
报错 : Missing BC Math or GMP extension
执行php -m 发现bcmath没有安装
安装bcmath
docker-php-ext-install bcmath
安装mysqli
docker-php-ext-install mysqli
上传文件不能超过2M
$ vi /usr/local/etc/php/conf.d/file.ini
upload_max_filesize=500M
post_max_size=500M
更新配置文件,重启容器
完整的Dockerfile
FROM arsaga/laravel-alpine:7.3-zip
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN echo -e "upload_max_filesize=500M\npost_max_size=500M" > /usr/local/etc/php/conf.d/filesize.ini
RUN pecl install igbinary && docker-php-ext-enable igbinary && \
pecl install redis && docker-php-ext-enable redis &&\
pecl install mongodb && docker-php-ext-enable mongodb && \
pecl install msgpack && docker-php-ext-enable msgpack && \
docker-php-ext-install bcmath