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.
2
Answers
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:taking care to include the necessary libraries first:
libfreetype6-dev, libjpeg-dev
andlibjpeg62-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.
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.