0

I'll build a Laravel 8 app. The PHP language level is PHP8. How can I integrate Swoole in my Dockerfile?

Actually I try it this way:

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

But if I build the Dockerfile, it always runs into this error:

------
 > [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

Does anyone has an idea? If you need more information about it, please let me know.

Regards, Manny

Manny
  • 79
  • 1
  • 10
  • Did you try to follow the instructions on swooles website? https://www.swoole.co.uk/docs/get-started/try-docker – Tom Regner Aug 19 '21 at 14:28
  • What base image do you use? – Gasol Aug 25 '21 at 14:14
  • @TomRegner: Yes I do. – Manny Aug 28 '21 at 08:26
  • @Gasol: Ubuntu:20.04 It works now. I'm not sure how, but maybe it has something to do with installing Node.JS in front of it?! I'll post my actualy working lines in the answer.. Thank you :) – Manny Aug 28 '21 at 08:29
  • @Manny: how can you follow the instructions I linked to (building swoole `by hand` in the docker file) and simultaneously use the deprecated pecl to try to install it? Just curious... – Tom Regner Sep 02 '21 at 10:50
  • @TomRegner: Sorry Tom! I meant "yes, I do. But it don't works. For me, my posted solution down below works. A friend of mine have had the same problem. For him the solution works too. – Manny Oct 31 '21 at 11:21

2 Answers2

0

...so I don't know why exactly, but it works for now. Maybe there where something wrong with my Node.JS installation above Swoole?!

Here is the for me working solution:

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
Manny
  • 79
  • 1
  • 10
0

It is a sample Dockerfile that uses the official PHP 8.0 (Debian) image and installs the Swoole through the PECL:

FROM php:8.0.12-cli-bullseye

# ...

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

It's also my complete 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
Milad Rahimi
  • 3,464
  • 3
  • 27
  • 39