Imagick Docker Alpine Linux Php8.2

I'm trying to install imagick on alpine linux for php8.2 and I don't really understand how to do it. I see that the imagick extension is still in testing. From what I read I can install it by specifying a different repository. However when I do so, I get an error: php82-common (no such package):. I can't find what this package php82-common is.

My dockerfile is as follows:

FROM laravelphp/vapor:php82

RUN apk --update add postgresql14-client

# INSTALL COMPOSER
RUN curl -s  | php
RUN alias composer='php composer.phar'

# INSTALL PHP EXTENSIONS
RUN apk add php82-pecl-imagick --repository=
RUN apk --update add imagemagick imagemagick-dev
RUN docker-php-ext-enable imagick

RUN docker-php-ext-install gd
RUN docker-php-ext-install exif

# Place application in Lambda application directory...
COPY . /var/task
2

3 Answers

Bellow one is working for me for php:8.2-fpm-alpine

RUN apk add --no-cache --virtual .build-deps $PHPIZE_DEPS imagemagick-dev \
&& pecl install imagick \
&& docker-php-ext-enable imagick \
&& apk del .build-deps

Easily install PHP extensions in Docker containers: special plugin

Also don't forget install Imagick to your system, in my case - Alpine Linux.

Full checked instructions for Docker file with Imagick OPCache Memcached and Redis (choose your plugins from official github page with the table there, here all plugins for Wordpress site as example):

FROM php:fpm-alpine
RUN apk update && apk add imagemagick ghostscript-fonts ghostscript
ADD  /usr/local/bin/
RUN chmod +x /usr/local/bin/install-php-extensions && \
    install-php-extensions opcache imagick memcached redis ssh2 sockets bcmath exif intl zip mysqli
COPY php/opcache.ini /usr/local/etc/php/conf.d/opcache.ini
COPY php/php.ini $PHP_INI_DIR/php.ini

It must work very well! Some adds... Create folder 'php' and add there a opcache.ini on your own config. Also add php.ini, configurate it on your own way.

The reason that the php82-pecl-imagick package is not found is that it graduated from Alpine's testing repository to community. Therefore, the community repository should be passed to apk's --repository option:

RUN apk add php82-pecl-imagick --repository=

In addition, you are missing the pecl command for installing the Imagick PHP extension:

RUN pecl install imagick

Here's the fixed Dockerfile, that builds successfully:

FROM laravelphp/vapor:php82

RUN apk --update add postgresql14-client

# INSTALL COMPOSER
RUN curl -s  | php
RUN alias composer='php composer.phar'

# INSTALL PHP EXTENSIONS
RUN apk add php82-pecl-imagick --repository=
RUN apk --update add imagemagick imagemagick-dev
RUN pecl install imagick
RUN docker-php-ext-enable imagick

RUN docker-php-ext-install gd
RUN docker-php-ext-install exif

# Place application in Lambda application directory...
COPY . /var/task

For reference, you can find the image build output here.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Robert Thorne

Robert Thorne

Automotive & Future Transportation Editor

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.

Share this article
Twitter Facebook Pinterest