I need to add imagemagick into my php 7.4 docker, so in file Dockerfile.yml I added :
FROM php:7.4.1-apache
RUN apt-get update && \
apt-get install -y \
python \
libfreetype6-dev \
libwebp-dev \
libjpeg62-turbo-dev \
libpng-dev \
libzip-dev \
nano \
mc \
git-core \
libmagickwand-dev --no-install-recommends && \
pecl install imagick && imagick && \
docker-php-ext-enable imagick && \
curl ...
RUN docker-php-ext-install \
gd pdo pdo_mysql zip gmp bcmath pcntl ldap sysvmsg exif && \
a2enmod rewrite
RUN install-php-extensions imagick
COPY virtualhost.conf /etc/apache2/sites-enabled/000-default.conf
But I got error:
Build process completed successfully
Installing '/usr/local/lib/php/extensions/no-debug-non-zts-20190902/imagick.so'
Installing '/usr/local/include/php/ext/imagick/php_imagick_shared.h'
install ok: channel://pecl.php.net/imagick-3.5.1
configuration option "php_ini" is not set to php.ini location
You should add "extension=imagick.so" to php.ini
/bin/sh: 1: imagick: not found
ERROR: Service 'web' failed to build: The command '/bin/sh -c apt-get update && apt-get install -y python libfreetype6-dev libwebp-dev libjpeg62-turbo-dev libpng-dev libzip-dev nano mc git-core libmagickwand-dev --no-install-recommends && pecl install imagick && imagick && docker-php-ext-enable imagick && curl build-essential openssl libssl-dev libgmp-dev libldap2-dev netcat locate && git clone https://github.com/nodejs/node.git && cd node && git checkout v12.0.0 && ./configure && make && make install' returned a non-zero code: 127
What is wrong in my Dockerfile.yml and how can it be fixed ?
UPDATED # 2: I modified Dockerfile.yml :
FROM php:7.4.1-apache
RUN apt-get update && \
# apt-get install -y \
apt-get install --assume-yes --no-install-recommends --quiet \
python \
libfreetype6-dev \
libwebp-dev \
libjpeg62-turbo-dev \
libpng-dev \
libzip-dev \
nano \
mc \
git-core \
libmagickwand-dev \
curl \
build-essential \
openssl \
libssl-dev \
libgmp-dev \
libldap2-dev \
netcat \
locate \
# composer \
&& git clone https://github.com/nodejs/node.git && \
cd node \
&& git checkout v12.0.0 \
&& ./configure \
&& make \
&& make install
RUN pecl install imagick \
&& docker-php-ext-enable imagick
RUN npm install cross-env
RUN npm install -g yarn
# RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-webp-dir=/usr/include/ --with-jpeg-dir=/usr/include/
RUN docker-php-ext-configure gd --with-freetype --with-jpeg
# READ https://github.com/docker-library/php/issues/912#issuecomment-559918036
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN docker-php-ext-install gd pdo pdo_mysql zip gmp bcmath pcntl ldap sysvmsg exif \
&& a2enmod rewrite
RUN apt-get install -y grep mlocate
RUN docker-php-ext-install imagick
COPY virtualhost.conf /etc/apache2/sites-enabled/000-default.conf
But running :
docker-compose up -d --build
I got erros in output :
Need to get 97.7 kB of archives.
After this operation, 504 kB of additional disk space will be used.
Get:1 http://deb.debian.org/debian buster/main amd64 mlocate amd64 0.26-3 [97.7 kB]
debconf: delaying package configuration, since apt-utils is not installed
Fetched 97.7 kB in 0s (729 kB/s)
Selecting previously unselected package mlocate.
(Reading database ... 22379 files and directories currently installed.)
Preparing to unpack .../mlocate_0.26-3_amd64.deb ...
Unpacking mlocate (0.26-3) ...
Setting up mlocate (0.26-3) ...
update-alternatives: using /usr/bin/mlocate to provide /usr/bin/locate (locate) in auto mode
update-alternatives: warning: skip creation of /usr/share/man/man1/locate.1.gz because associated file /usr/share/man/man1/mlocate.1.gz (of link group locate) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/man8/updatedb.8.gz because associated file /usr/share/man/man8/updatedb.mlocate.8.gz (of link group locate) doesn't exist
Adding group `mlocate' (GID 101) ...
Done.
Removing intermediate container 40f86f34f2af
---> edaee648df84
Step 10/11 : RUN docker-php-ext-install imagick
---> Running in a72d0887a6b0
error: /usr/src/php/ext/imagick does not exist
usage: /usr/local/bin/docker-php-ext-install [-jN] ext-name [ext-name ...]
ie: /usr/local/bin/docker-php-ext-install gd mysqli
/usr/local/bin/docker-php-ext-install pdo pdo_mysql
/usr/local/bin/docker-php-ext-install -j5 gd mbstring mysqli pdo pdo_mysql shmop
if custom ./configure arguments are necessary, see docker-php-ext-configure
Possible values for ext-name:
bcmath bz2 calendar ctype curl dba dom enchant exif ffi fileinfo filter ftp gd gettext gmp hash iconv imap intl json ldap mbstring mysqli oci8 odbc opcache pcntl pdo pdo_dblib pdo_firebird pdo_mysql pdo_oci pdo_odbc pdo_pgsql pdo_sqlite pgsql phar posix pspell readline reflection session shmop simplexml snmp soap sockets sodium spl standard sysvmsg sysvsem sysvshm tidy tokenizer xml xmlreader xmlrpc xmlwriter xsl zend_test zip
Some of the above modules are already compiled into PHP; please check
the output of "php -i" to see which modules are already loaded.
ERROR: Service 'web' failed to build: The command '/bin/sh -c docker-php-ext-install imagick' returned a non-zero code: 1
How can I fix it ?
Thanks in advance!
CodePudding user response:
The message
You should add "extension=imagick.so" to php.ini
is just a warning that is addressed later in your Dockerfile. The real error is caused by the execution of the non existing binary imagick
.
You can simplify your Dockerfile as follows:
FROM php:7.4.1-apache
RUN apt-get update \
&& apt-get install --assume-yes --no-install-recommends --quiet \
build-essential \
libmagickwand-dev
libmagickwand-dev \
&& apt-get clean all
RUN pecl install imagick \
&& docker-php-ext-enable imagick
This should fix the issue.
Output:
STEP 1/3: FROM php:7.4.1-apache
STEP 2/3: RUN apt-get update && apt-get install --assume-yes --no-install-recommends --quiet libmagickwand-dev && apt-get clean all
Get:1 http://security.debian.org/debian-security buster/updates InRelease [65.4 kB]
Get:2 http://deb.debian.org/debian buster InRelease [122 kB]
Get:3 http://deb.debian.org/debian buster-updates InRelease [51.9 kB]
Get:4 http://security.debian.org/debian-security buster/updates/main amd64 Packages [307 kB]
Get:5 http://deb.debian.org/debian buster/main amd64 Packages [7906 kB]
Get:6 http://deb.debian.org/debian buster-updates/main amd64 Packages [15.2 kB]
Fetched 8467 kB in 4s (2170 kB/s)
Reading package lists...
Reading package lists...
Building dependency tree...
Reading state information...
The following additional packages will be installed:
automake autotools-dev fontconfig fontconfig-config fonts-dejavu-core
gir1.2-freedesktop gir1.2-gdkpixbuf-2.0 gir1.2-glib-2.0 gir1.2-rsvg-2.0
icu-devtools imagemagick-6-common libblkid-dev libbz2-dev libcairo-gobject2
libcairo-script-interpreter2 libcairo2 libcairo2-dev libcroco3 libdatrie1
libde265-0 libdjvulibre-dev libdjvulibre-text libdjvulibre21 libelf1
libexif-dev libexif12 libexpat1-dev libffi-dev libfftw3-double3
libfontconfig1 libfontconfig1-dev libfreetype6 libfreetype6-dev libfribidi0
libgdk-pixbuf2.0-0 libgdk-pixbuf2.0-bin libgdk-pixbuf2.0-common
libgdk-pixbuf2.0-dev libgirepository-1.0-1 libglib2.0-0 libglib2.0-bin
libglib2.0-data libglib2.0-dev libglib2.0-dev-bin libgraphite2-3
libharfbuzz0b libheif1 libice-dev libice6 libicu-dev libicu63 libilmbase-dev
libilmbase23 libjbig-dev libjbig0 libjpeg-dev libjpeg62-turbo
libjpeg62-turbo-dev liblcms2-2 liblcms2-dev liblqr-1-0 liblqr-1-0-dev
libltdl-dev libltdl7 liblzma-dev liblzo2-2 libmagickcore-6-arch-config
libmagickcore-6-headers libmagickcore-6.q16-6 libmagickcore-6.q16-6-extra
libmagickcore-6.q16-dev libmagickwand-6-headers libmagickwand-6.q16-6
libmagickwand-6.q16-dev libmount-dev libmpdec2 libnuma1 libopenexr-dev
libopenexr23 libopenjp2-7 libopenjp2-7-dev libpango-1.0-0
libpangocairo-1.0-0 libpangoft2-1.0-0 libpcre16-3 libpcre3-dev libpcre32-3
libpcrecpp0v5 libpixman-1-0 libpixman-1-dev libpng-dev libpng16-16
libpthread-stubs0-dev libpython3-stdlib libpython3.7-minimal
libpython3.7-stdlib libreadline7 librsvg2-2 librsvg2-common librsvg2-dev
libselinux1-dev libsepol1-dev libsm-dev libsm6 libthai-data libthai0
libtiff-dev libtiff5 libtiffxx5 libwebp6 libwebpmux3 libwmf-dev libwmf0.2-7
libx11-6 libx11-data libx11-dev libx265-165 libxau-dev libxau6
libxcb-render0 libxcb-render0-dev libxcb-shm0 libxcb-shm0-dev libxcb1
libxcb1-dev libxdmcp-dev libxdmcp6 libxext-dev libxext6 libxml2 libxml2-dev
libxrender-dev libxrender1 libxt-dev libxt6 python3 python3-distutils
python3-lib2to3 python3-minimal python3.7 python3.7-minimal readline-common
shared-mime-info ucf uuid-dev x11-common x11proto-core-dev x11proto-dev
x11proto-xext-dev xorg-sgml-doctools xtrans-dev zlib1g-dev
Suggested packages:
autoconf-doc gnu-standards libcairo2-doc libfftw3-bin libfftw3-dev
freetype2-doc libglib2.0-doc libxml2-utils libice-doc icu-doc liblcms2-utils
libtool-doc liblzma-doc inkscape librsvg2-bin librsvg2-doc libsm-doc
libwmf-doc libwmf0.2-7-gtk libx11-doc libxcb-doc libxext-doc libxt-doc
python3-doc python3-tk python3-venv python3.7-venv python3.7-doc
binfmt-support readline-doc
Recommended packages:
bzip2-doc libexif-doc xdg-user-dirs libtool ghostscript gsfonts libjxr-tools
libpng-tools
The following NEW packages will be installed:
automake autotools-dev fontconfig fontconfig-config fonts-dejavu-core
gir1.2-freedesktop gir1.2-gdkpixbuf-2.0 gir1.2-glib-2.0 gir1.2-rsvg-2.0
icu-devtools imagemagick-6-common libblkid-dev libbz2-dev libcairo-gobject2
libcairo-script-interpreter2 libcairo2 libcairo2-dev libcroco3 libdatrie1
libde265-0 libdjvulibre-dev libdjvulibre-text libdjvulibre21 libelf1
libexif-dev libexif12 libexpat1-dev libffi-dev libfftw3-double3
libfontconfig1 libfontconfig1-dev libfreetype6 libfreetype6-dev libfribidi0
libgdk-pixbuf2.0-0 libgdk-pixbuf2.0-bin libgdk-pixbuf2.0-common
libgdk-pixbuf2.0-dev libgirepository-1.0-1 libglib2.0-bin libglib2.0-data
libglib2.0-dev libglib2.0-dev-bin libgraphite2-3 libharfbuzz0b libheif1
libice-dev libice6 libicu-dev libilmbase-dev libilmbase23 libjbig-dev
libjbig0 libjpeg-dev libjpeg62-turbo libjpeg62-turbo-dev liblcms2-2
liblcms2-dev liblqr-1-0 liblqr-1-0-dev libltdl-dev libltdl7 liblzma-dev
liblzo2-2 libmagickcore-6-arch-config libmagickcore-6-headers
libmagickcore-6.q16-6 libmagickcore-6.q16-6-extra libmagickcore-6.q16-dev
libmagickwand-6-headers libmagickwand-6.q16-6 libmagickwand-6.q16-dev
libmagickwand-dev libmount-dev libmpdec2 libnuma1 libopenexr-dev
libopenexr23 libopenjp2-7 libopenjp2-7-dev libpango-1.0-0
libpangocairo-1.0-0 libpangoft2-1.0-0 libpcre16-3 libpcre3-dev libpcre32-3
libpcrecpp0v5 libpixman-1-0 libpixman-1-dev libpng-dev libpng16-16
libpthread-stubs0-dev libpython3-stdlib libpython3.7-minimal
libpython3.7-stdlib libreadline7 librsvg2-2 librsvg2-common librsvg2-dev
libselinux1-dev libsepol1-dev libsm-dev libsm6 libthai-data libthai0
libtiff-dev libtiff5 libtiffxx5 libwebp6 libwebpmux3 libwmf-dev libwmf0.2-7
libx11-6 libx11-data libx11-dev libx265-165 libxau-dev libxau6
libxcb-render0 libxcb-render0-dev libxcb-shm0 libxcb-shm0-dev libxcb1
libxcb1-dev libxdmcp-dev libxdmcp6 libxext-dev libxext6 libxml2-dev
libxrender-dev libxrender1 libxt-dev libxt6 python3 python3-distutils
python3-lib2to3 python3-minimal python3.7 python3.7-minimal readline-common
shared-mime-info ucf uuid-dev x11-common x11proto-core-dev x11proto-dev
x11proto-xext-dev xorg-sgml-doctools xtrans-dev zlib1g-dev
The following packages will be upgraded:
libglib2.0-0 libicu63 libxml2
3 upgraded, 150 newly installed, 0 to remove and 46 not upgraded.
Need to get 73.0 MB of archives.
After this operation, 234 MB of additional disk space will be used.
[...]
--> 69135d97974
STEP 3/3: RUN pecl install imagick && docker-php-ext-enable imagick
WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
downloading imagick-3.5.1.tgz ...
Starting to download imagick-3.5.1.tgz (301,411 bytes)
.............................................................done: 301,411 bytes
33 source files, building
running: phpize
Configuring for:
PHP Api Version: 20190902
Zend Module Api No: 20190902
Zend Extension Api No: 320190902
Please provide the prefix of ImageMagick installation [autodetect] :
Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in PEAR/Builder.php on line 405
Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in /usr/local/lib/php/PEAR/Builder.php on line 405
building in /tmp/pear/temp/pear-build-defaultuserIJdbl7/imagick-3.5.1
running: /tmp/pear/temp/imagick/configure --with-php-config=/usr/local/bin/php-config --with-imagick
[...]
checking if ImageMagick version is at least 6.2.4... found version 6.9.10
checking for MagickWand.h or magick-wand.h header... /usr/include/ImageMagick-6/wand/MagickWand.h
checking PHP version is at least 5.3.2... yes. found 7.4.1
libs
-lMagickWand-6.Q16 -lMagickCore-6.Q16
checking for MagickGetVersion... yes
[...]
Build complete.
Don't forget to run 'make test'.
running: make INSTALL_ROOT="/tmp/pear/temp/pear-build-defaultuserIJdbl7/install-imagick-3.5.1" install
Installing shared extensions: /tmp/pear/temp/pear-build-defaultuserIJdbl7/install-imagick-3.5.1/usr/local/lib/php/extensions/no-debug-non-zts-20190902/
Installing header files: /tmp/pear/temp/pear-build-defaultuserIJdbl7/install-imagick-3.5.1/usr/local/include/php/
running: find "/tmp/pear/temp/pear-build-defaultuserIJdbl7/install-imagick-3.5.1" | xargs ls -dils
7097429 8 drwxr-xr-x. 3 root root 4096 Oct 11 07:24 /tmp/pear/temp/pear-build-defaultuserIJdbl7/install-imagick-3.5.1
7097485 8 drwxr-xr-x. 3 root root 4096 Oct 11 07:24 /tmp/pear/temp/pear-build-defaultuserIJdbl7/install-imagick-3.5.1/usr
7097487 8 drwxr-xr-x. 4 root root 4096 Oct 11 07:24 /tmp/pear/temp/pear-build-defaultuserIJdbl7/install-imagick-3.5.1/usr/local
7097498 8 drwxr-xr-x. 3 root root 4096 Oct 11 07:24 /tmp/pear/temp/pear-build-defaultuserIJdbl7/install-imagick-3.5.1/usr/local/include
7097501 8 drwxr-xr-x. 3 root root 4096 Oct 11 07:24 /tmp/pear/temp/pear-build-defaultuserIJdbl7/install-imagick-3.5.1/usr/local/include/php
7097503 8 drwxr-xr-x. 3 root root 4096 Oct 11 07:24 /tmp/pear/temp/pear-build-defaultuserIJdbl7/install-imagick-3.5.1/usr/local/include/php/ext
7097505 8 drwxr-xr-x. 2 root root 4096 Oct 11 07:24 /tmp/pear/temp/pear-build-defaultuserIJdbl7/install-imagick-3.5.1/usr/local/include/php/ext/imagick
7097507 4 -rw-r--r--. 1 root root 1828 Oct 11 07:24 /tmp/pear/temp/pear-build-defaultuserIJdbl7/install-imagick-3.5.1/usr/local/include/php/ext/imagick/php_imagick_shared.h
7097489 8 drwxr-xr-x. 3 root root 4096 Oct 11 07:24 /tmp/pear/temp/pear-build-defaultuserIJdbl7/install-imagick-3.5.1/usr/local/lib
7097491 8 drwxr-xr-x. 3 root root 4096 Oct 11 07:24 /tmp/pear/temp/pear-build-defaultuserIJdbl7/install-imagick-3.5.1/usr/local/lib/php
7097493 8 drwxr-xr-x. 3 root root 4096 Oct 11 07:24 /tmp/pear/temp/pear-build-defaultuserIJdbl7/install-imagick-3.5.1/usr/local/lib/php/extensions
7097495 8 drwxr-xr-x. 2 root root 4096 Oct 11 07:24 /tmp/pear/temp/pear-build-defaultuserIJdbl7/install-imagick-3.5.1/usr/local/lib/php/extensions/no-debug-non-zts-20190902
7097483 1608 -rwxr-xr-x. 1 root root 1646360 Oct 11 07:24 /tmp/pear/temp/pear-build-defaultuserIJdbl7/install-imagick-3.5.1/usr/local/lib/php/extensions/no-debug-non-zts-20190902/imagick.so
Build process completed successfully
Installing '/usr/local/include/php/ext/imagick/php_imagick_shared.h'
Installing '/usr/local/lib/php/extensions/no-debug-non-zts-20190902/imagick.so'
install ok: channel://pecl.php.net/imagick-3.5.1
configuration option "php_ini" is not set to php.ini location
You should add "extension=imagick.so" to php.ini
--> 3ee934f2bbd
3ee934f2bbdc1639a02325939d9fc1eefeb16c5803edc33424c18ecc616f7fb1