gulp imagimine plugin throwinf error while optimizing images - docker

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

Related

Install sqlsrv driver for laravel project with docker and php-alpine image

I need to connect on remote MSSQL database, I use docker enviroment. How to add sqlsrv driver, I have a docker file, as follows:
FROM php:8.0.5-fpm-alpine
ADD ./php/www.conf /usr/local/etc/php-fpm.d/www.conf
RUN apk add --no-cache tzdata
ENV TZ Europe/Skopje
RUN addgroup -g 1000 laravel && adduser -G laravel -g laravel -s /bin/sh -D laravel
RUN mkdir -p /var/www/html
RUN chown laravel:laravel /var/www/html
WORKDIR /var/www/html
RUN docker-php-ext-install pdo pdo_mysql
This is what I find on an alpine-based Dockerfile to install it:
RUN wget https://download.microsoft.com/download/e/4/e/e4e67866-dffd-428c-aac7-8d28ddafb39b/msodbcsql17_17.5.1.1-1_amd64.apk && \
wget https://download.microsoft.com/download/e/4/e/e4e67866-dffd-428c-aac7-8d28ddafb39b/mssql-tools_17.5.1.1-1_amd64.apk && \
apk add --allow-untrusted msodbcsql17_17.5.1.1-1_amd64.apk && \
apk add --allow-untrusted mssql-tools_17.5.1.1-1_amd64.apk && \
apk add --no-cache --virtual .phpize-deps $PHPIZE_DEPS unixodbc-dev && \
pecl install pdo_sqlsrv && \
docker-php-ext-enable pdo_sqlsrv && \
apk del .phpize-deps && \
rm msodbcsql17_17.5.1.1-1_amd64.apk && \
rm mssql-tools_17.5.1.1-1_amd64.apk
It doesn't works, but it compiled with no errors.
Can you provide mabye another dockerfile solutino.
I get error:
SQLSTATE[HY000]: [Microsoft][ODBC Driver 17 for SQL Server]Protocol
error in TDS stream
I ran over the same Problem and found this GitHub-Thread
So there is some Microsoft documentation about installing the driver on alpine linux.
Combining those two sources gets a current version of the driver. I included the following lines in my Dockerfile and they compile without problems:
RUN wget https://download.microsoft.com/download/8/6/8/868e5fc4-7bfe-494d-8f9d-115cbcdb52ae/msodbcsql18_18.1.2.1-1_amd64.apk && \
wget https://download.microsoft.com/download/8/6/8/868e5fc4-7bfe-494d-8f9d-115cbcdb52ae/mssql-tools18_18.1.1.1-1_amd64.apk && \
apk add --allow-untrusted msodbcsql18_18.1.2.1-1_amd64.apk && \
apk add --allow-untrusted mssql-tools18_18.1.1.1-1_amd64.apk && \
apk add --no-cache --virtual .phpize-deps $PHPIZE_DEPS unixodbc-dev && \
pecl install pdo_sqlsrv && \
docker-php-ext-enable pdo_sqlsrv && \
apk del .phpize-deps && \
rm msodbcsql18_18.1.2.1-1_amd64.apk && \
rm mssql-tools18_18.1.1.1-1_amd64.apk

Docker: Build fail on another host with same configuration

I'm using Docker in a developement environment. I have two pc, both with same OS (kubuntu 20.04) and same docker version.
In one the dockerfile build without errors, in the other fails with
$ docker build -t letsjump/mydockername -f docker-data/webserver73/Dockerfile .
#...lot of compile output...
configure: error: unrecognized options: --with-freetype, --with-jpeg, --with-freetype, --with-webp
The command '/bin/sh -c curl -sL https://deb.nodesource.com/setup_12.x | bash - && apt-key update && DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" install $CUSTOM_BUILD_DEPS $PHPIZE_DEPS sendmail git mariadb-client openssh-client nano netcat linkchecker nodejs build-essential libzip-dev libz-dev wget unixodbc odbcinst unixodbc-dev gnupg libwebp-dev libonig-dev --no-install-recommends && npm -g install npm#latest && docker-php-ext-configure gd --with-freetype --with-jpeg --with-freetype --with-webp && docker-php-ext-configure bcmath && docker-php-ext-configure calendar && docker-php-ext-configure pdo_odbc --with-pdo-odbc=unixODBC,/usr && docker-php-ext-install gd intl pdo_mysql mysqli mbstring opcache zip bcmath calendar soap && pecl install memcached-3.1.5 && echo extension=memcached.so >> /usr/local/etc/php/conf.d/memcached.ini && printf "\n" | pecl -d preferred_state=beta install xdebug' returned a non-zero code: 1
In both hosts I have the same OS (kubuntu 20.04 desktop) and almost the same Docker version.
In this host the dockerfile build succesfully:
$ docker --version
Docker version 19.03.5, build 633a0ea838
In this other not:
$ docker --version
Docker version 19.03.12, build 48a66213fe
This is the dockerfile:
# Dockerfile (c) letsjump 2018
FROM php:7.3-apache
MAINTAINER letsjump <letsjump#xxx>
WORKDIR /
COPY ./docker-data/webserver73/ /
RUN chown -R "$APACHE_RUN_USER:$APACHE_RUN_GROUP" "/usr/local/bin";
RUN chmod -R +xr "/usr/local/bin/";
EXPOSE 80
EXPOSE 443
RUN useradd -ms /dev/null dbmaker
RUN chown -R dbmaker:dbmaker /home/dbmaker
# define build dependency lists
# inherited from PHP base image:
# PHPIZE_DEPS=autoconf dpkg-dev file g++ gcc libc-dev libpcre3-dev make pkg-config re2c
ENV CUSTOM_BUILD_DEPS \
unzip \
libmemcached-dev \
libicu-dev \
libfreetype6-dev \
libjpeg-dev \
libjpeg62-turbo-dev \
libxml2-dev \
zlib1g-dev \
libpng-dev
# list of other packages which could be deinstalled at the end
ENV CUSTOM_REMOVE_LIST cpp \
cpp-4.9 \
g++-4.9 \
gcc-4.9 \
libgcc-4.9-dev \
libhashkit-dev \
libsasl2-dev \
libstdc++-4.9-dev
RUN apt-get update && apt-get install -my gnupg
# Install system packages for PHP extensions recommended for Yii 2.0 Framework
# Install PHP extensions required for Yii 2.0 Framework
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash - && \
apt-key update && \
DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" install \
$CUSTOM_BUILD_DEPS \
$PHPIZE_DEPS \
sendmail \
git \
mariadb-client \
openssh-client \
nano \
netcat \
linkchecker \
nodejs \
build-essential \
libzip-dev \
libz-dev \
wget \
unixodbc \
odbcinst \
unixodbc-dev \
gnupg \
libwebp-dev \
libonig-dev \
--no-install-recommends && \
npm -g install npm#latest && \
docker-php-ext-configure gd --with-freetype --with-jpeg --with-freetype --with-webp && \
docker-php-ext-configure bcmath && \
docker-php-ext-configure calendar && \
docker-php-ext-configure pdo_odbc --with-pdo-odbc=unixODBC,/usr && \
docker-php-ext-install gd \
intl \
pdo_mysql \
mysqli \
mbstring \
opcache \
zip \
bcmath \
calendar \
soap && \
# printf "\n" | pecl -d preferred_state=beta install xdebug
pecl install memcached-3.1.5 && \
echo extension=memcached.so >> /usr/local/etc/php/conf.d/memcached.ini && \
printf "\n" | pecl -d preferred_state=beta install xdebug
# apt-get remove -y $PHPIZE_DEPS $CUSTOM_BUILD_DEPS $CUSTOM_REMOVE_LIST && \
# dpkg --purge $(dpkg -l | awk '/^rc/ { print $2 }') && \
# apt-get clean && \
# rm -rf /usr/src/php* && \
# rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
#set -x \
# && cd /usr/src/php/ext/odbc \
# && phpize \
# && sed -ri 's#^ *test +"\$PHP_.*" *= *"no" *&& *PHP_.*=yes *$##&#g' configure \
# odbc
# docker-php-ext-configure odbc --with-unixODBC=/usr --with-dbmaker=/home/dbmaker/5.2 && \
# docker-php-ext-configure odbc --with-unixODBC=/usr --with-dbmaker=/home/dbmaker/5.2 --with-adabas=no && \
# Install less-compiler
RUN npm install -g \
less \
lesshint \
uglify-js \
uglifycss
ENV PHP_USER_ID=33 \
PHP_ENABLE_XDEBUG=1 \
VERSION_COMPOSER_ASSET_PLUGIN=^1.4.6 \
VERSION_PRESTISSIMO_PLUGIN=^0.3.10 \
PATH=/var/www/:/root/.composer/vendor/bin:$PATH \
TERM=linux \
COMPOSER_ALLOW_SUPERUSER=1 \
GITHUB_API_TOKEN=${GITHUB_API_TOKEN}
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- \
--install-dir=/usr/local/bin \
--filename=composer --version=1.10.16 && \
composer global require --optimize-autoloader \
"fxp/composer-asset-plugin:${VERSION_COMPOSER_ASSET_PLUGIN}" \
"hirak/prestissimo:${VERSION_PRESTISSIMO_PLUGIN}" && \
composer global dumpautoload --optimize && \
composer clear-cache
RUN chown -R 1000:33 /var/www
# Install Yii framework bash autocompletion
RUN curl -L https://raw.githubusercontent.com/yiisoft/yii2/master/contrib/completion/bash/yii \
-o /etc/bash_completion.d/yii
# enabling specific apache2 modules
# enabling specific apache2 modules
RUN a2enmod rewrite && \
service apache2 restart
WORKDIR /var/www
Yes, the dockerfile is probably a mess, with a lot of adds on the fly. But why it compiles in one host and in the other not?
UPDATE
After reading the reasonable answer of aankhen, I emptied the docker-data/webserver73 folder which in any case did not contain any relevant code except one apache virtualhost and one xdebug.ini configuration file in their relative folders.
The build failed again with the same error as above.
I also want to point out that the wevserver73 folder contains the exact same files as the one on the other host with the same owner and rights.
I would expect failures to happen sporadically and periodically with this dockerfile. Why? Because you haven't pinned the versions of the majority of tools you're installing. You implicitly install the latest version of a bunch of GNU/Linux libraries and then explicitly install the latest version of npm and you follow this up by using npm to install the latest version of a bunch of javascript modules. I can see that you pin the versions of some libs, but to guarantee repeatability you have to pin everything.
Also, as #Aankhen said in the comments, you also have a copy command that is copying files from the local filesystem, which could contain anything and again is unlikely to result in a portable repeatable image.
The solution to this is a) pin everything, or b) use a registry to share an image that has been built once and rely on a pinned version of that. Generally, banks and large corporations require the pinning solution, and less regulated industries often go with the registry solution.
I answer to my question:
As Software-engineer said in his answer, pin, pin, pin.
In this case it was the PHP's mantainers (questionable) choice to change the Debian release within a minor version of the docker image (php:7.3-apache). Here they switched from stretch to buster.
So the new pulled php:7.3-apache image had a completely different OS and different dependent library and behaviors.
So, as Software-engineer said, the right and the fastest solution to this problem is to pin the PHP image to a tag related to the distribution: php:7.3-apache-stretch.
The slower and unstable solution, in case you want to use the unpinned version, is to adapt the GD configure options to the new release:
...
docker-php-ext-configure gd --with-gd --with-webp-dir --with-jpeg-dir \
--with-png-dir --with-zlib-dir --with-freetype-dir && \
...
taking care to include the necessary libraries first: libfreetype6-dev, libjpeg-dev and libjpeg62-turbo-dev
But this will require a manual pull from the server for any host that has a non recent build of the same image.

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.

Cannot get npm installed app to be present in final Docker image

I have added installation of the Vega tools to the docker-asciidoctor Dockerfile and they are present when running the bats tests, but when I run the image they are no longer present.
I am quite new to Docker.
I have also tried some variations of adding the dir node_modules to the path, but nothing works.
In all cases the directory where the Vega tools are installed to is simply not in the image.
I am adding the Vega tools like this:
...
&& npm install --build-from-source -g vega-cli vega vega-lite vega-embed \
&& echo `which vl2vg` \
...
which provides this output:
...
/usr/bin/vl2png -> /usr/lib/node_modules/vega-lite/bin/vl2png
/usr/bin/vl2svg -> /usr/lib/node_modules/vega-lite/bin/vl2svg
/usr/bin/vl2vg -> /usr/lib/node_modules/vega-lite/bin/vl2vg
/usr/bin/vg2pdf -> /usr/lib/node_modules/vega-cli/bin/vg2pdf
/usr/bin/vg2png -> /usr/lib/node_modules/vega-cli/bin/vg2png
/usr/bin/vg2svg -> /usr/lib/node_modules/vega-cli/bin/vg2svg
...
/usr/bin/vl2vg
just as one would expect.
And the test that one of the tools are there looks like this:
#test "vl2vg is installed and in the path" {
docker run -t --rm "${DOCKER_IMAGE_NAME_TO_TEST}" which vl2vg
}
That passes.
I would expect the Vega tools to be available in the image when I do the following:
docker run -it --entrypoint /bin/sh asciidoctor/docker-asciidoctor
/documents # which vl2vg
which: no vl2vg in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin)
Given the output from the build of the image I would have expected to see /usr/bin/vl2vg and /usr/lib/node_modules is not there.
For completeness here is the Docker file and the steps taken:
FROM alpine:3.9
LABEL MAINTAINERS="Guillaume Scheibel <guillaume.scheibel#gmail.com>, Damien DUPORTAL <damien.duportal#gmail.com>"
ARG asciidoctor_version=2.0.9
ARG asciidoctor_confluence_version=0.0.2
ARG asciidoctor_pdf_version=1.5.0.alpha.17
ARG asciidoctor_diagram_version=1.5.16
ARG asciidoctor_epub3_version=1.5.0.alpha.9
ARG asciidoctor_mathematical_version=0.3.0
ARG asciidoctor_revealjs_version=2.0.0
ENV ASCIIDOCTOR_VERSION=${asciidoctor_version} \
ASCIIDOCTOR_CONFLUENCE_VERSION=${asciidoctor_confluence_version} \
ASCIIDOCTOR_PDF_VERSION=${asciidoctor_pdf_version} \
ASCIIDOCTOR_DIAGRAM_VERSION=${asciidoctor_diagram_version} \
ASCIIDOCTOR_EPUB3_VERSION=${asciidoctor_epub3_version} \
ASCIIDOCTOR_MATHEMATICAL_VERSION=${asciidoctor_mathematical_version} \
ASCIIDOCTOR_REVEALJS_VERSION=${asciidoctor_revealjs_version}
# Installing package required for the runtime of
# any of the asciidoctor-* functionnalities
RUN apk add --no-cache \
bash \
curl \
ca-certificates \
findutils \
font-bakoma-ttf \
graphviz \
inotify-tools \
make \
openjdk8-jre \
py2-pillow \
py-setuptools \
python2 \
ruby \
ruby-mathematical \
ttf-liberation \
unzip \
which
RUN addgroup --system appgroup && adduser -S appuser -G appgroup
WORKDIR /data/
# Installing Ruby Gems needed in the image
# including asciidoctor itself
RUN apk add --no-cache --virtual .rubymakedepends \
build-base \
libxml2-dev \
ruby-dev \
&& gem install --no-document \
"asciidoctor:${ASCIIDOCTOR_VERSION}" \
"asciidoctor-confluence:${ASCIIDOCTOR_CONFLUENCE_VERSION}" \
"asciidoctor-diagram:${ASCIIDOCTOR_DIAGRAM_VERSION}" \
"asciidoctor-epub3:${ASCIIDOCTOR_EPUB3_VERSION}" \
"asciidoctor-mathematical:${ASCIIDOCTOR_MATHEMATICAL_VERSION}" \
asciimath \
"asciidoctor-pdf:${ASCIIDOCTOR_PDF_VERSION}" \
"asciidoctor-revealjs:${ASCIIDOCTOR_REVEALJS_VERSION}" \
coderay \
epubcheck:3.0.1 \
haml \
kindlegen:3.0.3 \
pygments.rb \
rake \
rouge \
slim \
thread_safe \
tilt \
&& apk add --update npm \
# && npm -g config set user root \
&& apk --no-cache --virtual .canvas-build-deps add \
build-base \
cairo-dev \
jpeg-dev \
pango-dev \
giflib-dev \
pixman-dev \
pangomm-dev \
libjpeg-turbo-dev \
freetype-dev \
&& apk --no-cache add \
pixman \
cairo \
pango \
giflib \
# && npm -g config set user root \
&& npm config set user 0 \
&& npm config set unsafe-perm true \
&& npm install --build-from-source -g vega-cli vega vega-lite vega-embed \
&& echo `which vl2vg` \
# && apk del .canvas-build-deps \
&& apk del -r --no-cache .rubymakedepends
ENV PATH /data/node_modules/.bin:$PATH
ENV NODE_PATH /data/node_modules/
# Installing Python dependencies for additional
# functionnalities as diagrams or syntax highligthing
RUN apk add --no-cache --virtual .pythonmakedepends \
build-base \
python2-dev \
py2-pip \
&& pip install --upgrade pip \
&& pip install --no-cache-dir \
actdiag \
'blockdiag[pdf]' \
nwdiag \
Pygments \
seqdiag \
&& apk del -r --no-cache .pythonmakedepends
USER appuser
WORKDIR /documents
VOLUME /documents
CMD ["/bin/bash"]
The build command is (lifted from the Makefile):
DOCKER_IMAGE_NAME ?= docker-asciidoctor
DOCKERHUB_USERNAME ?= asciidoctor
DOCKER_IMAGE_TEST_TAG ?= $(shell git rev-parse --short HEAD)
build:
docker build \
-t $(DOCKER_IMAGE_NAME_TO_TEST) \
-f Dockerfile \
$(CURDIR)/
Testing is with:
test:
bats $(CURDIR)/tests/*.bats
where one of the tests is the one mentioned above.
The root cause for this was that I wasn't using the image that I had just built since I wasn't tagging the image.
docker tag asciidoctor/docker-asciidoctor:442d4d0 asciidoctor/docker-asciidoctor:latest
and then things worked.
Thanks for this! - super helpful, especially the tip about npm install -g canvas and vega-cli using the npm - g config set user root.
I was building from a different base image: mhart/alpine-node. Here's the Dockerfile that worked for me..
FROM mhart/alpine-node:12.16.2
WORKDIR /app
COPY *.jar .
RUN apk add --no-cache \
python2 \
build-base \
g++ \
cairo-dev \
jpeg-dev \
pango-dev \
bash \
imagemagick
RUN npm -g config set user root \
&& npm install -g canvas \
&& npm install -g vega vega-lite vega-cli
# USER root
# RUN apk update
# RUN apk fetch openjdk8
# RUN apk add openjdk8
The four lines commented out at the each are for installing java as well.

Docker Alpine - Enable GD JPEG support

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 && \
...

Resources