0

我将构建一个 Laravel 8 应用程序。PHP 语言级别为 PHP8。如何将 Swoole 集成到我的 Dockerfile 中?

其实我是这样尝试的:

RUN pecl channel-update https://pecl.php.net/channel.xml \
    && pecl install swoole

但是如果我构建 Dockerfile,它总是会遇到这个错误:

------
 > [11/19] RUN pecl channel-update https://pecl.php.net/channel.xml  && pecl install swoole:
#14 0.283 /bin/sh: 1: pecl: not found
------
failed to solve: rpc error: code = Unknown desc = executor failed running [/bin/sh -c pecl channel-update https://pecl.php.net/channel.xml  && pecl install swoole]: exit code: 127

有人有想法吗?如果您需要有关它的更多信息,请告诉我。

问候,曼尼

4

2 回答 2

0

它是一个使用官方 PHP 8.0 (Debian) 镜像并通过 PECL 安装 Swoole 的示例 Dockerfile:

FROM php:8.0.12-cli-bullseye

# ...

RUN pecl install swoole
RUN docker-php-ext-enable swoole

这也是我完整的 Dockerfile:

FROM php:8.0.12-cli-bullseye

# Install system dependencies
RUN apt-get update && apt-get install -y \
    curl \
    libicu-dev \
    libpng-dev \
    libonig-dev \
    libxml2-dev \
    git \
    cron \
    zip \
    unzip

# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Install PHP extensions
RUN pecl install redis swoole
RUN docker-php-ext-install pdo_mysql exif pcntl bcmath gd intl soap
RUN docker-php-ext-enable redis swoole
RUN docker-php-ext-configure intl

RUN sed -i -e "s/upload_max_filesize = .*/upload_max_filesize = 1G/g" \
        -e "s/post_max_size = .*/post_max_size = 1G/g" \
        -e "s/memory_limit = .*/memory_limit = 512M/g" \
        /usr/local/etc/php/php.ini-production \
        && cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini

# Set working directory
WORKDIR /app

# Get latest Composer and install
COPY --from=composer:2.1.9 /usr/bin/composer /usr/bin/composer
于 2022-02-07T08:19:17.500 回答
0

...所以我不知道为什么,但它现在有效。也许我在 Swoole 上的 Node.JS 安装有问题?!

这是适合我的工作解决方案:

ENV NODE_VERSION=16.5
ENV NVM_DIR=/root/.nvm
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
RUN . "$NVM_DIR/nvm.sh" \
    && nvm install ${NODE_VERSION}
RUN . "$NVM_DIR/nvm.sh" \
    && nvm use v${NODE_VERSION}
RUN . "$NVM_DIR/nvm.sh" \
    && nvm alias default v${NODE_VERSION}
ENV PATH="/root/.nvm/versions/node/v${NODE_VERSION}/bin/:${PATH}"
RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        npm
RUN npm install -g yarn

RUN pecl channel-update https://pecl.php.net/channel.xml \
    && pecl install swoole
于 2021-08-28T08:33:16.340 回答