Dockerfile for php laravel unable to install pecl install pcov ssh2 swoole

673 Views Asked by At

This is my Dockerfile to create a docker image for a laravel 8/9 application.

FROM php:8.1.9-fpm-alpine
RUN apk --no-cache upgrade && \
    apk --no-cache add bash git sudo openssh  libxml2-dev oniguruma-dev autoconf gcc g++ make npm freetype-dev libjpeg-turbo-dev libpng-dev libzip-dev





# PHP: Install php extensions
RUN pecl channel-update pecl.php.net
RUN pecl install pcov ssh2 swoole
RUN docker-php-ext-configure gd --with-freetype --with-jpeg
RUN docker-php-ext-install mbstring xml  pcntl gd zip sockets pdo  pdo_mysql bcmath soap
RUN docker-php-ext-enable mbstring xml gd  zip pcov pcntl sockets bcmath pdo  pdo_mysql soap swoole


RUN docker-php-ext-install pdo pdo_mysql sockets
RUN curl -sS https://getcomposer.org/installer​ | php -- \
     --install-dir=/usr/local/bin --filename=composer

COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
COPY --from=spiralscout/roadrunner:2.4.2 /usr/bin/rr /usr/bin/rr

WORKDIR /app
COPY . .

RUN composer install
RUN composer require laravel/octane spiral/roadrunner

RUN npm install --global yarn
RUN yarn
RUN yarn prod


RUN php artisan key:generate
RUN php artisan octane:install --server="swoole"

CMD php artisan octane:start --server="swoole" --host="0.0.0.0" 
EXPOSE 8000

All seems to be fine, however when I started to create the image docker with :

docker build -t laravelapp:1.0 .

it throwed this error:

Dockerfile:11
--------------------
   9 |     # PHP: Install php extension
  10 |     RUN pecl channel-update pecl.php.net
  11 | >>> RUN pecl install pcov ssh2 swoole
  12 |     RUN docker-php-ext-configure gd --with-freetype --with-jpeg
  13 |     RUN docker-php-ext-install mbstring xml  pcntl gd zip sockets pdo  pdo_mysql bcmath soap
--------------------
ERROR: failed to solve: process "/bin/sh -c pecl install pcov ssh2 swoole" did not complete successfully: exit code: 1
ubuntu@ubuntu:~/laravel-projects/iptv-manager-laravel8$

It seems that pecl command is not working properly, I don't know what to do. I have installed docker inside a raspberry pi 4 with ubuntu server.

Any idea guys to fix this problem I will apppreciate it.

thanks.

1

There are 1 best solutions below

0
Carlos Matias Pumas On

I had the same problem, and you can fix it by installing the following dependency:

libssh2 libssh2-dev

Since in my case, the error was thrown at me because I did not have these libraries installed. In the APK installation line you need to add those libraries. If so, it gave you the same error as me.

configure: error: The required libssh2 library was not found. You can obtain

I hope you find it useful.