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.
Related
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
I have a docker Image with the following Entrypoint.
ENTRYPOINT [ "sh", "-c", "/var/www/html/app/Console/cake schema update -y && /var/www/html/app/Console/cake migration && apache2-foreground"]
Now I want to use portainer.io to manage docker swarm. I created a new service to where I want to set the entrypoint (instead of in the Image). So I deleted the entrypoint In the dockerfile, and added it into "Image" > "Entrypoint". I added:
sh -c /var/www/html/app/Console/cake schema update -y && /var/www/html/app/Console/cake migration && apache2-foreground
However, the containers of the service are failing to start. Without the entrypoint, the containers are starting. Here is an example of the Dockerfile, where the Entrypoint is set.
#start with base Image from php
FROM php:7.3-apache
#install system dependencies and enable PHP modules
RUN apt-get update && apt-get install -y \
libicu-dev \
libpq-dev \
libmcrypt-dev \
mysql-client \
git \
zip \
unzip \
libzip-dev \
&& docker-php-ext-configure zip --with-libzip \
&& docker-php-ext-install zip \
&& rm -r /var/lib/apt/lists/* \
&& docker-php-ext-configure pdo_mysql --with-pdo-mysql=mysqlnd \
&& docker-php-ext-install \
intl \
mbstring \
pcntl \
pdo_mysql \
pdo_pgsql \
pgsql \
opcache \
gettext
# zip \
# mcrypt \
#configure imap for mails
RUN apt-get update && \
apt-get install -y \
libc-client-dev libkrb5-dev && \
rm -r /var/lib/apt/lists/*
RUN docker-php-ext-configure imap --with-kerberos --with-imap-ssl && \
docker-php-ext-install -j$(nproc) imap
#install mcrypt
RUN apt-get update \
&& apt-get install -y libmcrypt-dev \
&& rm -rf /var/lib/apt/lists/* \
&& pecl install mcrypt-1.0.2 \
&& docker-php-ext-enable mcrypt
#install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer
#change uid and gid of apache to docker user uid/gid
RUN usermod -u 1000 www-data && groupmod -g 1000 www-data
# enable apache module rewrite
RUN a2enmod rewrite
#change ownership of our applications
RUN chown -R www-data:www-data /var/www/html
#Copy file to start schema update on startup
ENTRYPOINT [ "sh", "-c", "/var/www/html/app/Console/cake schema update -y && /var/www/html/app/Console/cake migration && apache2-foreground"]
EXPOSE 80
How do I have to set the Entrypoint? When I set it a portainer, it is later shown under the section CDM.
On a debian machine, I suddenly cannot install ssmtp via the following
apt-get update && apt-get install ssmtp
Before it was all working seamlessly up until now.
Also just an FYI.
I am doing this on a dockerFile on a debian container.
Just for your perusal this is the docker file I am running
FROM php:fpm
RUN apt-get update && apt-get install -q -y \
git g++ libcurl4-gnutls-dev libicu-dev libmcrypt-dev \
libpq-dev libxml2-dev \
unzip zlib1g-dev \
procps\
zip \
libzip-dev \
ssmtp mailutils && rm -rf /var/lib/apt/lists/*
RUN docker-php-ext-install \
pdo_mysql mysqli curl json mbstring pdo pdo_pgsql \
&& docker-php-ext-enable mysqli
RUN docker-php-ext-configure pdo_mysql
RUN echo "hostname=localhost.localdomain" > /etc/ssmtp/ssmtp.conf
RUN echo "root=root#example.com" >> /etc/ssmtp/ssmtp.conf
RUN echo "mailhub=maildev" >> /etc/ssmtp/ssmtp.conf
RUN echo "sendmail_path=sendmail -i -t" >> /usr/local/etc/php/conf.d/php-sendmail.ini
RUN echo "localhost localhost.localdomain" >> /etc/hosts
ENV TZ=Asia/Manila
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer
RUN curl -sSL https://phar.phpunit.de/phpunit.phar -o /usr/bin/phpunit && chmod +x /usr/bin/phpunit
I ran into the same issue, but it has to do with the fact that the package sSMTP package is currently unmaintained.
This package has been orphaned since 2019-03-19. msmtp can be used as an alternative.
So the fix would be replacing your sSMTP package with the suggested msmtp package.
I use docker-compose to build my containers and on a state I checkout private repository and I build the project inside container with composer.
I have the following structure
- docker-project
-- docker //here I keep the containers
--- apache
---- Dockerfile // the content what I posted
-- docker-compose.yml
-- src //this is the mounted folder where I can work on project
After build I would expect that the build project would show up in the mounted folder but instead I get empty folders here is my compose yml
apache:
container_name: apache2
build:
context: ./docker/apache
ports:
- 80:80
- 443:443
links:
- database
restart: always
volumes:
- ./src:/var/www/
- ./docker/logs/apache2/:/var/log/apache2/
- ~/.ssh/id_rsa:/root/.ssh/id_rsa
- ./docker/apache/sites/:/etc/apache2/sites-enabled
and here I have the docker file
FROM php:7.1-apache
ENV APACHE_DOCUMENT_ROOT /var/www
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
curl \
openssl \
openssh-server \
sendmail \
sendmail-bin \
mailutils \
libicu-dev \
libmemcached-dev \
libz-dev \
libpq-dev \
libjpeg-dev \
libfreetype6-dev \
libssl-dev \
libmcrypt-dev \
libxml2-dev \
libbz2-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
libjpeg62-turbo-dev \
zlib1g-dev \
libicu-dev \
g++ \
libxml2-dev \
git \
&& rm -rf /var/lib/apt/lists/*
# Install various PHP extensions which are required to build project
RUN docker-php-ext-configure bcmath --enable-bcmath \
&& docker-php-ext-configure pcntl --enable-pcntl \
&& docker-php-ext-configure pdo_mysql --with-pdo-mysql \
&& docker-php-ext-configure pdo_pgsql --with-pgsql \
&& docker-php-ext-configure mbstring --enable-mbstring \
&& docker-php-ext-configure soap --enable-soap \
&& docker-php-ext-install \
bcmath \
json \
intl \
mbstring \
mcrypt \
mysqli \
pcntl \
pdo_mysql \
pdo_pgsql \
soap \
sockets \
zip \
&& docker-php-ext-configure gd \
--enable-gd-native-ttf \
--with-jpeg-dir=/usr/lib \
--with-freetype-dir=/usr/include/freetype2 && \
docker-php-ext-install gd
##install xdebug and enable it. We need this for php unit coverage
RUN yes | pecl install xdebug \
&& docker-php-ext-enable xdebug
RUN yes | pecl install mongodb \
&& docker-php-ext-enable mongodb
RUN update-ca-certificates
# install composer to can install dependencies
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
&& php composer-setup.php --install-dir=/usr/local/bin --filename=composer \
&& php -r "unlink('composer-setup.php');"
RUN mkdir /root/.ssh
RUN rm -rf /var/www/project
WORKDIR /var/www/
RUN git checkout path/to/repo
RUN ls -l /var/www
WORKDIR /repo
RUN composer install
RUN ls -l
on docker-compose build I see that the project will be builded but on
docker-compose upthe folder is empty
What I'm missing in this case?
You are mounting a volume on /var/www when starting the container.
/var/www will be the same as ./src/www on the host machine, replacing anything that was added to /var/www during the build of the image.
Consider using the composer docker image or make sure to install the dependencies to another directory. Check out the vendor_dir key in composer.json
Example:
composer.json
{
"require": {
},
"config": {
"vendor-dir": "/var/www/vendor/"
}
}
Docker image build:
...
RUN mkdir -p /var/www/vendor/
COPY composer.json /var/www/vendor/
RUN cd /var/www/vendor/ && composer install
RUN mkidr -p /var/www/app
...
docker-compose.yml
volumes:
- ./src:/var/www/app
I could give a way of currently we are working. Rather cloning the repo like this what we do, we clone the repo in the local machine.
You have standard docker image that you have created from
php:7.1-apache with required softwares that you need to run the project.
Then you clone your project to you host machine.(think into src folder)
You run the composer install locally.
Then as you have defined the docker-compose.yml mount your src folder into /var/www/
I'm trying to install drupal console in docker (under Linux Antergos). I've the following error :
Warning: mkdir(): Permission denied in phar:///usr/local/bin/drupal/vendor/drupal/console-core/src/Utils/ConfigurationManager.php on line 49
Here is my PHP dockerfile :
FROM php:7.0-fpm
RUN usermod -u 1000 www-data
# Set timezone
RUN rm /etc/localtime
RUN ln -s /usr/share/zoneinfo/Europe/Bruxelles /etc/localtime
RUN "date"
RUN apt-get update && apt-get install -y \
git \
unzip \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng12-dev \
mysql-client \
&& docker-php-ext-install -j$(nproc) iconv mcrypt \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd \
&& docker-php-ext-install mysqli pdo pdo_mysql mcrypt zip mbstring opcache json
# Install Xdebug / Redis
RUN pecl install redis \
&& pecl install xdebug \
&& docker-php-ext-enable redis xdebug
# Set the Drush version.
ENV DRUSH_VERSION 8.1.2
# Install Drush 8 with the phar file.
RUN curl -fsSL -o /usr/local/bin/drush "https://github.com/drush-ops/drush/releases/download/$DRUSH_VERSION/drush.phar" && \
chmod +x /usr/local/bin/drush
# Download console.
RUN curl https://drupalconsole.com/installer -L -o drupal.phar
# Install console.
RUN mv drupal.phar /usr/local/bin/drupal && \
chmod +x /usr/local/bin/drupal && \
drupal init --override
# Create drush-backups dir
RUN mkdir /var/www/drush-backups/
USER 1000
WORKDIR /var/www/html
To solve the problem I had to install Drupal Console by composer. There is certainly another solution, but it's work with it.