Docker Alpine - Enable GD JPEG support - docker

I'm having a problem getting GD Jpeg support through the Alpine image for PHP-FPM. I've tried every combination I can think of to get this working. Below is a snippet from my Dockerfile:
FROM php:7.1-fpm-alpine
RUN apk update \
&& apk upgrade \
&& apk add --no-cache \
freetype \
libpng \
libjpeg-turbo \
freetype-dev \
libpng-dev \
jpeg-dev \
libjpeg \
libjpeg-turbo-dev \
RUN docker-php-ext-configure gd \
--with-freetype-dir=/usr/lib/ \
--with-png-dir=/usr/lib/ \
--with-jpeg-dir=/usr/lib/ \
--with-gd
RUN NUMPROC=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || 1) \
&& docker-php-ext-install -j${NUMPROC} gd
When I shell into the container and run php -r 'print_r(gd_info());', I get the following:
Array
(
[GD Version] => bundled (2.1.0 compatible)
[FreeType Support] =>
[GIF Read Support] => 1
[GIF Create Support] => 1
[JPEG Support] =>
[PNG Support] => 1
[WBMP Support] => 1
[XPM Support] =>
[XBM Support] => 1
[WebP Support] =>
[JIS-mapped Japanese Font Support] =>
)
[JPEG Support] has an empty value. I've tried replacing /usr/lib/ with:
/usr/
/usr/include/
with no success. The problem is that when I try to install Magento 2 through Composer I get the error:
Warning: call_user_func() expects parameter 1 to be a valid callback, function 'imagecreatefromjpeg' not found or invalid function name in /var/www/html/vendor/magento/framework/Image/Adapter/Gd2.php on line 65'.
Has anyone experienced this, and if so, how did you solve it?
Thank you

could you try removing the last slash in your first RUN command and check ?
FROM php:7.1-fpm-alpine
RUN apk update \
&& apk upgrade \
&& apk add --no-cache \
freetype-dev \
libpng-dev \
jpeg-dev \
libjpeg-turbo-dev
RUN docker-php-ext-configure gd \
--with-freetype-dir=/usr/lib/ \
--with-png-dir=/usr/lib/ \
--with-jpeg-dir=/usr/lib/ \
--with-gd
RUN NUMPROC=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || 1) \
&& docker-php-ext-install -j${NUMPROC} gd
This is my working Image using Linux Alpine :
FROM php:7-fpm-alpine
# Install all dependencies.
RUN apk --no-cache update \
&& apk --no-cache upgrade \
&& apk add --no-cache $PHPIZE_DEPS \
freetype-dev \
libjpeg-turbo-dev \
libpng-dev && \
docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/ && \
docker-php-ext-install -j$(getconf _NPROCESSORS_ONLN) gd && \
...

Related

Visual studio code devcontainer error reading from server: EOF

I'm trying to do a devcontainer setup with vscode on linux (fedora 37) but I always get the error you can see in the image link below
failed to receive status: rpc error: code = Unavailable desc = error reading from server: EOF
These are my configuration files:
Dockerfile:
FROM php:7.4-apache
RUN apt-get update && apt-get install -y \
git \
unzip \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
libzip-dev \
libicu-dev \
libc-client-dev \
libkrb5-dev \
libmagickwand-dev && \
docker-php-ext-configure gd --with-freetype --with-jpeg=/usr/include/ --enable-gd && \
docker-php-ext-install -j$(nproc) gd && \
docker-php-ext-configure intl && \
PHP_OPENSSL=yes docker-php-ext-configure imap --with-kerberos --with-imap-ssl && \
docker-php-ext-install -j$(nproc) imap && \
docker-php-ext-install zip && \
docker-php-ext-install mysqli && \
docker-php-ext-install pdo_mysql && \
docker-php-ext-install intl && \
docker-php-ext-install calendar && \
docker-php-ext-install exif && \
docker-php-ext-install gettext && \
docker-php-ext-install sockets && \
yes '' | pecl install imagick && docker-php-ext-enable imagick && \
a2enmod rewrite && \
a2enmod headers && \
a2enmod cgi && \
a2enmod proxy_fcgi && \
apt-get remove -y libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
libzip-dev \
libicu-dev \
libc-client-dev \
libkrb5-dev \
libmagickwand-dev && \
apt-get clean -y
RUN sed -i -e '/.* rights="none".*pattern="PDF"/s/ rights="none"/ rights="read|write"/g' /etc/ImageMagick-6/policy.xml
COPY --from=composer:2.5 /usr/bin/composer /usr/bin/composer
devcontainer.json:
{
"name": "PHP",
"build": {
"context": ".",
"dockerfile": "Dockerfile"
},
"forwardPorts": [ "8000:80" ],
"customizations": {
"vscode": {
"extensions": [
"donjayamanne.git-extension-pack",
"waderyan.gitblame",
"ms-azuretools.vscode-docker",
"p1c2u.docker-compose",
"ms-vscode-remote.remote-ssh",
"TabNine.tabnine-vscode",
"DEVSENSE.phptools-vscode",
"xdebug.php-pack"
]
}
},
"workspaceMount":"source=${localWorkspaceFolder},target=/workspace,type=bind,consistency=cached",
"workspaceFolder": "/workspace",
}
Thank you very much for the help
The information I found on the internet says that the problem is docker, but docker is fine.
I run my docker build and it finishes successfully, but devconteiner throws the error every time
This is most likely related to a bug in Docker stack, introduced in recent Docker 23 (check your version to make sure the below applies to you).
VSC issue: https://github.com/microsoft/vscode-remote-release/issues/7958. There you can find a workaround and links to upstream trackers that deal with the issue directly.
I can confirm the workaround of disabling BUILDKIT_INLINE_CACHE works, that is setting the following in .devcontainer.json allows for VSC to start:
{
"build": {
"args": {
"BUILDKIT_INLINE_CACHE": "0"
}
}
}
The issue itself is supposed to be fixed already, but may not have landed in your distribution yet.

APCu is not enabled ? Cant create fixtures

I have a problem using the command:
php bin / console d: f: l
[Symfony \ Component \ Cache \ Exception \ CacheException]
APCu is not activated
While Symfony 3 recognizes acpu extension very well.
For information, I am on docker and I have successfully installed the ACPu extension.
Symfony detects the cache well but I don't know why the script doesn't want to start. I tried to take inspiration from other DockerFile but still the same problem.
My PHP DockerFile:
FROM php:7.2-fpm-alpine
MAINTAINER Zakariae Filali <filali.zakariae#gmail.com>
ARG TIMEZONE
ENV WORKDIR "/var/www/symfony"
ENV EXT_APCU_VERSION=5.1.17
RUN apk upgrade --update && apk --no-cache add \
git autoconf tzdata openntpd libcurl curl-dev coreutils \
libmcrypt-dev freetype-dev libxpm-dev libjpeg-turbo-dev libvpx-dev \
libpng-dev libressl-dev libxml2-dev postgresql-dev icu-dev \
yarn
RUN docker-php-source extract \
# ext-apcu
&& mkdir -p /usr/src/php/ext/apcu \
&& curl -fsSL https://github.com/krakjoe/apcu/archive/v$EXT_APCU_VERSION.tar.gz | tar xvz -C /usr/src/php/ext/apcu --strip 1 \
&& docker-php-ext-install apcu \
# cleanup
&& docker-php-source delete
RUN apk add --update --no-cache --virtual .build-dependencies $PHPIZE_DEPS \
&& pecl install apcu \
&& docker-php-ext-enable apcu \
&& pecl clear-cache \
&& apk del .build-dependencies
RUN apk add --no-cache --virtual build-dependencies icu-dev libxml2-dev freetype-dev libpng-dev libjpeg-turbo-dev g++ make autoconf
RUN docker-php-ext-configure intl \
&& docker-php-ext-configure opcache \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ \
--with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/ \
--with-xpm-dir=/usr/include/
RUN docker-php-ext-install -j$(nproc) gd iconv pdo pdo_mysql pdo_pgsql curl \
bcmath mbstring json xml xmlrpc zip intl opcache
RUN yes '' | pecl install -f mcrypt
RUN echo "extension=mcrypt.so" > /usr/local/etc/php/conf.d/mcrypt.ini
RUN ln -snf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime && echo ${TIMEZONE} > /etc/timezone \
&& printf '[PHP]\ndate.timezone = "%s"\n', ${TIMEZONE} > /usr/local/etc/php/conf.d/tzone.ini \
&& "date"
RUN curl -sS https://getcomposer.org/installer | \
php -- --install-dir=/usr/local/bin --filename=composer
RUN rm -rf /var/cache/apk/* \
&& find / -type f -iname \*.apk-new -delete \
&& rm -rf /var/cache/apk/*
RUN mkdir -p ${WORKDIR}
RUN chown www-data:www-data -R ${WORKDIR}
RUN version=$(php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;") \
&& curl -A "Docker" -o /tmp/blackfire-probe.tar.gz -D - -L -s https://blackfire.io/api/v1/releases/probe/php/alpine/amd64/$version \
&& mkdir -p /tmp/blackfire \
&& tar zxpf /tmp/blackfire-probe.tar.gz -C /tmp/blackfire \
&& mv /tmp/blackfire/blackfire-*.so $(php -r "echo ini_get ('extension_dir');")/blackfire.so \
&& printf "extension=blackfire.so\nblackfire.agent_socket=tcp://blackfire:8707\n" > $PHP_INI_DIR/conf.d/blackfire.ini \
&& rm -rf /tmp/blackfire /tmp/blackfire-probe.tar.gz
WORKDIR ${WORKDIR}
CMD ["php-fpm"]
You have to enable apc for cli.
If you launch php -i, you should have something like that:
apc.coredump_unmap => Off => Off
apc.enable_cli => Off => Off
apc.enabled => On => On
apc.entries_hint => 4096 => 4096
apc.gc_ttl => 3600 => 3600
apc.mmap_file_mask => no value => no value
apc.preload_path => no value => no value
apc.serializer => php => php
apc.shm_segments => 1 => 1
apc.shm_size => 32M => 32M
apc.slam_defense => On => On
apc.smart => 0 => 0
apc.ttl => 0 => 0
apc.use_request_time => On => On
apc.writable => /tmp => /tmp
You can see apc.enable_cli is set to Off.
So, add this line to your Dockerfile:
RUN echo "apc.enable_cli=1" >> /usr/local/etc/php/conf.d/docker-php-ext-apcu.ini

gulp imagimine plugin throwinf error while optimizing images

I have such a gulp task
gulp.task('images', () => {
return gulp.src('assets/images/**/*')
.pipe($.cache($.imagemin()))
.pipe(gulp.dest('public/build/images'));
});
and it throwing error in this line .pipe($.cache($.imagemin())) for me:
events.js:167
throw er; // Unhandled 'error' event
^
Error: write callback called multiple times
at DestroyableTransform.afterTransform (/var/www/vhosts/devgenix/node_modules/readable-stream/lib/_stream_transform.js:84:31)
at EventEmitter.signals.on.err (/var/www/vhosts/devgenix/node_modules/gulp-cache/lib/index.js:451:7)
at EventEmitter.emit (events.js:182:13)
at DestroyableTransform.onError (/var/www/vhosts/devgenix/node_modules/gulp-cache/lib/index.js:288:15)
at Object.onceWrapper (events.js:273:13)
at DestroyableTransform.emit (events.js:187:15)
at Immediate.<anonymous> (/var/www/vhosts/devgenix/node_modules/through2-concurrent/through2-concurrent.js:37:14)
at runCallback (timers.js:706:11)
at tryOnImmediate (timers.js:676:5)
at processImmediate (timers.js:658:5)
but for other developers on their machines, all works fine.
I'm running all the code under the custom alpine docker container with preinstalled node (other devs no), so maybe it's an issue and I just need to install some missing dependency but I can't figure out what is wrong.
My docker file is actually for PHP with the node, here is the docker file content:
FROM php:7.1-fpm-alpine
ENV ZMQ_VERSION 4.3.1
ENV BUILD_DEPS autoconf file gcc libc-dev make g++ pkgconf re2c git
RUN apk add --update --no-cache --virtual .build-deps $BUILD_DEPS
# Error code: 127
RUN apk add --no-cache --virtual .php-build-deps \
nasm \
libsodium \
freetype-dev \
libmcrypt-dev \
postgresql-dev \
libxml2-dev \
zlib-dev cyrus-sasl-dev libmemcached-dev \
# the next line is for node and npm packages (node-sass requires python/make/g++ to build something)
python \
&& apk add --update nodejs nodejs-npm \
# for GD
bash \
freetype libpng libjpeg-turbo freetype-dev libpng-dev libjpeg-turbo-dev \
# just good to have installed
ca-certificates wget \
## Install git (we'll never delete it)
#&& apk add --no-cache git \
&& docker-php-ext-configure gd \
--with-gd \
--with-freetype-dir=/usr/include/ \
--with-png-dir=/usr/include/ \
--with-jpeg-dir=/usr/include/ \
&& NPROC=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || 1) \
## Installable modules
&& docker-php-ext-install -j${NPROC} iconv mcrypt bcmath pdo_mysql opcache pgsql pdo_pgsql soap pcntl exif zip gd \
&& apk del --no-cache freetype-dev libpng-dev libjpeg-turbo-dev \
## Memcached
&& git clone https://github.com/php-memcached-dev/php-memcached.git \
&& cd php-memcached \
&& git checkout php7 \
&& phpize \
&& ./configure --disable-memcached-sasl \
&& make \
&& cp modules/memcached.so $(php-config --extension-dir) \
&& docker-php-ext-enable memcached \
## Composer
&& cd ~ \
&& curl -sS https://getcomposer.org/installer | php \
&& mv composer.phar /usr/local/bin/composer \
## Gulp
&& npm install -g gulp \
## Cleanup
&& rm -rf /var/cache/apk/*
RUN docker-php-ext-configure calendar && docker-php-ext-install calendar
ADD www.conf /usr/local/etc/php-fpm.d
ADD php-fpm.conf /usr/local/etc
ADD php.ini /usr/local/etc/php/
WORKDIR /var/www/vhosts/devgenix/
#EXPOSE 22
CMD ["php-fpm", "--fpm-config", "/usr/local/etc/php-fpm.conf"]
Maybe someone has any ideas why it's not working for me? Thanks!
updated
npm version: 6.4.1
gulp version: 3.9.1
gulp-imagemin version: 4.1.0
I solve the issue by adding libjpeg-turbo libjpeg-turbo-dev libpng libpng-dev automake dependencies to my docker file

How to install wkhtmltopdf on Docker php-fpm Alpine Linux?

I installed Wkhtmltopdf on Alpine Docker with the following command:
apk add --no-cache wkhtmltopdf
However when I try to run wkhtmltopdf I get:
/usr/bin/wkhtmltopdf "test.html" "test.pdf"
Cannot mix incompatible Qt library (version 0x50c03) with this library (version 0x50c00)
Aborted (core dumped)
How can I fix that?
EDIT:
Seems like the issue is that some other package installs not compatable qt version. Here's my Dockerfile:
RUN apk --no-cache update \
&& apk --no-cache upgrade \
&& apk add --no-cache \
mysql-client \
php7-mysqli \
php7-pdo \
freetype \
libpng \
freetype-dev \
libpng-dev \
jpeg-dev \
libjpeg \
libjpeg-turbo-dev \
wget \
zlib-dev \
ttf-freefont \
fontconfig \
xvfb \
libxrender-dev \
gettext \
gettext-dev \
libxml2-dev \
gnu-libiconv-dev \
autoconf \
g++ \
git \
bash \
wkhtmltopdf
You cannot install wkhtmltopdf from alpine repositories starting of 3.15 version https://pkgs.alpinelinux.org/packages?name=wkhtmltopdf&branch=edge&repo=&arch=&maintainer=
If you want to use wkhtmltopdf in the newer alpine (3.17 below). You can copy bin files from other images like https://github.com/Surnet/docker-wkhtmltopdf and install related libraries.
Here is Dockerfile:
FROM surnet/alpine-wkhtmltopdf:3.16.2-0.12.6-full as wkhtmltopdf
FROM php:8.2-fpm-alpine3.17 AS app
# wkhtmltopdf install dependencies
RUN apk add --no-cache \
libstdc++ \
libx11 \
libxrender \
libxext \
libssl1.1 \
ca-certificates \
fontconfig \
freetype \
ttf-droid \
ttf-freefont \
ttf-liberation \
# more fonts
;
# wkhtmltopdf copy bins from ext image
COPY --from=wkhtmltopdf /bin/wkhtmltopdf /bin/libwkhtmltox.so /bin/
# install php extensions, apache/nginx etc.

Can't install package on alpine though I can see it in the ui

I was running php7 on alpine without a hitch for the last week till today when I rebuilt my image and now nothing works. I get the errors:
/ # apk add php7
ERROR: unsatisfiable constraints:
php7 (missing):
required by: world[php7]
for every package , extension I was trying to install and that previously worked. Here's the RUN command I was using to setup php7:
RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories && \
apk update && \
apk upgrade && \
apk add --update \
php7-mcrypt \
php7-soap \
php7-openssl \
php7-gmp \
php7-pdo_odbc \
php7-json \
php7-dom \
php7-pdo \
php7-zip \
php7-mysqli \
php7-sqlite3 \
php7-pdo_pgsql \
php7-bcmath \
php7-gd \
php7-odbc \
php7-pdo_mysql \
php7-pdo_sqlite \
php7-gettext \
php7-xmlreader \
php7-xmlrpc \
php7-bz2 \
php7-iconv \
php7-pdo_dblib \
php7-curl \
php7-ctype \
php7-fpm
All the above extensions installed flawlessly last week. What I'm I missing?
Proof the packages do exist: https://pkgs.alpinelinux.org/packages?name=php7-*&branch=&repo=&arch=&maintainer=
Package php7 has been moved from the testing to the community repository, so you have to replace http://dl-cdn.alpinelinux.org/alpine/edge/testing with http://dl-cdn.alpinelinux.org/alpine/edge/community.
You should use the official PHP 7 Alpine image on DockerHub.
Then, per the image documentation, use the docker-php-ext-install command in your Dockerfile:
FROM php:7-fpm-alpine
RUN apk update \
&& apk add libmcrypt-dev \
&& docker-php-ext-install mcrypt mysqli pdo_mysql \
&& rm /var/cache/apk/*
This may initially look a little strange, but it works and is the officially supported Docker approach.
We provide the helper scripts docker-php-ext-configure,
docker-php-ext-install, and docker-php-ext-enable to more easily
install PHP extensions.
DockerHub - PHP

Resources