我有这个Dockerfile。当我尝试运行它时,在Composer Update行中返回错误,表明未安装扩展。

这是因为未在php.ini上激活GRPC

我的问题是,如何通过终端激活它?

FROM php:7.2-apache
WORKDIR /var/www/html
COPY . ./
RUN apt-get update && apt-get install -y -q nodejs npm curl unzip git rake ruby-ronn zlib1g-dev libpng-dev && apt-get clean
RUN apt-get install php7.2=dev php-pear phpunit
RUN curl -sS https://getcomposer.org/installer | php
RUN mv composer.phar /usr/local/bin/composer
RUN pecl install grpc
RUN docker-php-ext-install mbstring
RUN docker-php-ext-install zip
RUN docker-php-ext-install gd
RUN npm install
RUN npm install -g gulp-cli
RUN composer update
RUN gulp --env=production
EXPOSE 80 443

最佳答案

您忘记激活grcp扩展名,可以使用#install protoc注释下的代码进行激活,RUN php -r "echo extension_loaded('grpc') ? 'yes' : 'no';"会显示消息是否已激活
我认为这种方式更好,更简洁:

FROM php:7-apache

RUN apt-get update && apt-get install -y -q git rake ruby-ronn zlib1g-dev && apt-get clean
# install composer
RUN cd /usr/local/bin && curl -sS https://getcomposer.org/installer | php
RUN cd /usr/local/bin && mv composer.phar composer
RUN pecl install grpc
#install protoc
RUN mkdir -p /tmp/protoc && \
    curl -L https://github.com/google/protobuf/releases/download/v3.2.0/protoc-3.2.0-linux-x86_64.zip > /tmp/protoc/protoc.zip && \
    cd /tmp/protoc && \
    unzip protoc.zip && \
    cp /tmp/protoc/bin/protoc /usr/local/bin && \
    cd /tmp && \
    rm -r /tmp/protoc && \
    docker-php-ext-enable grpc

RUN php -r "echo extension_loaded('grpc') ? 'yes' : 'no';"
WORKDIR /app
COPY . /app
RUN composer install
RUN npm install
RUN npm install -g gulp-cli
RUN gulp --env=production
EXPOSE 8181

关于docker - 如何通过Dockerfile激活GRPC PHP扩展?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57678009/

10-15 20:09