I am trying upgrade this docker file from 7.3 to 7.4 but getting executor failed error.
Detailed error:
executor failed running [/bin/sh -c docker-php-ext-install bcmath
ctype dom gd hash iconv intl mbstring
mysqli opcache pdo_mysql simplexml sockets soap
sodium xsl zip ;]: exit code: 2
FROM php:7.4-fpm as base
ENV COMPOSER_HOME=/tmp/composer
ENV APCU_VERSION=5.1.18
RUN apt-get update && apt-get install -y --no-install-recommends gnupg \
netcat \
sudo \
libicu-dev \
libfreetype6-dev \
libjpeg-dev \
libpng-dev \
libsodium-dev \
libxml2-dev \
libxslt-dev \
libzip-dev \
rsync \
unzip \
git \
openssh-client \
;
RUN pecl install apcu-${APCU_VERSION}
RUN docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/
RUN docker-php-ext-install \
bcmath \
ctype \
dom \
gd \
hash \
iconv \
intl \
mbstring \
mysqli \
opcache \
pdo_mysql \
simplexml \
sockets \
soap \
sodium \
xsl \
zip \
;
RUN docker-php-ext-enable apcu
RUN echo "memory_limit=1G" >> /usr/local/etc/php/conf.d/zz-memory-limit-php.ini
RUN echo "apc.enable=1" >> /usr/local/etc/php/conf.d/zz-apcu.ini
RUN echo "apc.enable_cli=1" >> /usr/local/etc/php/conf.d/zz-apcu.ini
RUN echo "opcache.memory_consumption=512MB" >> /usr/local/etc/php/conf.d/zz-opcache.conf
RUN echo "opcache.max_accelerated_files=60000" >> /usr/local/etc/php/conf.d/zz-opcache.conf
RUN echo "opcache.consistency_checks=0" >> /usr/local/etc/php/conf.d/zz-opcache.conf
RUN echo "opcache.validate_timestamps=0" >> /usr/local/etc/php/conf.d/zz-opcache.conf
RUN echo "opcache.enable_cli=1" >> /usr/local/etc/php/conf.d/zz-opcache.conf
FROM base as build
RUN curl https://files.magerun.net/n98-magerun2.phar -o /usr/local/bin/magerun \
&& chmod 755 /usr/local/bin/magerun
RUN mkdir -p -m 0775 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts
RUN mkdir -p -m 0775 ~/.ssh && ssh-keyscan github.com >> /var/www/.ssh
# USER www-data
WORKDIR /var/www/html
ARG COMPOSER_AUTH
COPY --from=composer:1 /usr/bin/composer /usr/bin/composer
RUN composer global require hirak/prestissimo
COPY auth.json auth.json
COPY composer.json composer.json
COPY composer.lock composer.lock
RUN --mount=type=ssh,id=id_rsa php -d memory_limit=2G $(which composer) install --no-progress --no-dev
COPY app/etc/config.php app/etc/config.php
COPY bin bin
FROM build as app
ENV MAGE_MODE=production
RUN php -d memory_limit=2G bin/magento setup:di:compile
RUN composer dump-autoload --optimize --apcu
RUN php -d memory_limit=2G bin/magento setup:static-content:deploy -f
RUN rm -rf /var/www/html/var/cache
RUN rm -rf /var/www/html/var/page_cache
RUN rm -rf /var/www/html/var/session
COPY --chown=www-data app/etc/env.docker.php app/etc/env.php
i had a similar issue today.
Seems that in php7.4 iconv his a native library.
So you should try to remove it from your Dockerfile and see if it works.
Even if it's an 6 month old issue, i hope it could help someone.
Chears.
Related
That's my dockerfile
FROM php:7.4-fpm
# Install GD
RUN apt update \
&& apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng-dev \
&& docker-php-ext-configure gd \
&& docker-php-ext-install -j$(nproc) pdo_mysql bcmath exif gd
# Arguments defined in docker-compose.yml
ARG user
ARG uid
# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
curl \
libpng-dev \
libonig-dev \
libxml2-dev \
zip \
unzip
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd
# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Create system user to run Composer and Artisan Commands
RUN useradd -G www-data,root -u $uid -d /home/$user $user
RUN mkdir -p /home/$user/.composer && \
chown -R $user:$user /home/$user
# Set working directory
WORKDIR /var/www
USER $user
When I try to use conversions from Spatie/Medialibrary I has an error:
Call to undefined function Intervention\Image\Gd\imagejpeg()
I tried everything from here and other sites, but it still not helps.
A lot of solutions for the LAMP stack, but I have Nginx.
I'm a newbie at docker and don't understand what's going wrong.
Please help :)
upd.
Last version of dockerfile:
FROM php:7.4-fpm
# Arguments defined in docker-compose.yml
ARG user
ARG uid
RUN apt-get update && apt-get install -y \
zlib1g-dev \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev
# Install GD
RUN docker-php-ext-configure gd --enable-gd --with-freetype --with-jpeg
RUN cd /usr/src/php/ext/gd && make
RUN cp /usr/src/php/ext/gd/modules/gd.so /usr/local/lib/php/extensions/no-debug-non-zts-20190902/gd.so
RUN docker-php-ext-install -j$(nproc) gd
# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
curl \
libfontconfig1-dev \
xclip \
libjpeg62 \
libonig-dev \
libxml2-dev \
zip \
unzip
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd
# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Create system user to run Composer and Artisan Commands
RUN useradd -G www-data,root -u $uid -d /home/$user $user
RUN mkdir -p /home/$user/.composer && \
chown -R $user:$user /home/$user
# Set working directory
WORKDIR /var/www
USER $user
I tried a --with-jpeg and --with-freetype, also tried the trick with the folder creation. But still JPEG Support and Freetype support is false.
Your docker container is missing the php-gd Extension.
This is how we install it in our dockerfile:
RUN docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd \
docker-php-ext-install is a script in the official Docker-Container:
https://hub.docker.com/_/php
So in your file you could do this:
RUN apt-get update && apt-get install -y \
git \
curl \
libfontconfig1-dev \
xclip \
libjpeg62 \
libonig-dev \
libxml2-dev \
zip \
unzip \
&& docker-php-ext-configure gd \
&& docker-php-ext-install -j$(nproc) gd
I'm trying to build for legacy php5.3 inside my windows WSL2 ubuntu via latest docker desktop,
https://hub.docker.com/r/orsolin/docker-php-5.3-apache
The file content I put it this way
FROM orsolin/php:5.3-apache
RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf
RUN apt-get update
RUN apt-get install -y \
git \
zip \
curl \
sudo \
unzip \
libicu-dev \
libbz2-dev \
libpng-dev \
libjpeg-dev \
libmcrypt-dev \
libreadline-dev \
libfreetype6-dev \
g++
RUN docker-php-ext-install \
bz2 \
intl \
bcmath \
opcache \
calendar \
pdo_mysql \
mysqli
COPY docker/apache/000-default.conf /etc/apache2/sites-available/000-default.conf
RUN a2enmod rewrite headers
RUN curl -sS https://getcomposer.org/installer | php
RUN mv composer.phar /usr/local/bin/composer
RUN chmod +x /usr/local/bin/composer
RUN composer self-update
ARG uid
RUN useradd -G www-data,root -u $uid -d /home/devuser devuser
RUN mkdir -p /home/devuser/.composer && \
chown -R devuser:devuser /home/devuser
EXPOSE 80
It come out with such error, not sure why...
=> ERROR [internal] load metadata for docker.io/orsolin/php:5.3-apache 3.3s
=> [auth] orsolin/php:pull token for registry-1.docker.io 0.0s
------
> [internal] load metadata for docker.io/orsolin/php:5.3-apache:
------
failed to solve with frontend dockerfile.v0: failed to create LLB definition: pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed
ERROR: Service 'web' failed to build : Build failed
I don't have logs when running bin/phpunit on the console in my web container.
My web dockerfile:
FROM php:7.4-apache
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
libzip-dev \
sudo \
unzip \
zip \
git \
nano \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd \
&& docker-php-ext-install zip pdo pdo_mysql opcache \
&& apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN pecl install xdebug && docker-php-ext-enable xdebug
COPY ./apache/chat-app.conf /etc/apache2/sites-available/000-default.conf
COPY ./php/php.ini /usr/local/etc/php/conf.d/app.ini
RUN curl --silent --show-error https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN rm /etc/localtime
RUN ln -s /usr/share/zoneinfo/Europe/Paris /etc/localtime
RUN "date"
RUN sed -ri -e 's!/var/www/html!/var/www!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/!/var/www!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf
RUN a2enmod rewrite
RUN a2enmod headers
When i run phpunit:
What's wrong ?
I've tried to add xdebug but it's also not working.
I'm on ubuntu 20.04 and I use Tilix console.
Finally, I removed symfony/phpunit-bridge package and use phpunit/phpunit instead.
composer remove --dev symfony/phpunit-bridge
composer require --dev phpunit/phpunit
Now, logs are displaying on the console in my web container.
I'm trying to install PHP Composer via Docker to be able to run composer as if it was installed on my host (MacOS) locally.
FROM php:7.2.13-apache
# install supporting packages
RUN apt-get update && apt-get install -y --fix-missing \
xz-utils \
build-essential \
pkg-config \
git-core \
autoconf \
libjpeg62-turbo-dev \
libsodium-dev \
libpng-dev \
libcurl4-openssl-dev \
libpq-dev \
libpspell-dev \
libsqlite3-dev \
libmagickwand-dev \
libzip-dev \
imagemagick \
subversion \
python \
g++ \
curl \
vim \
wget \
netcat \
chrpath
# install officially supported php extensions
RUN docker-php-ext-install \
iconv \
sodium \
opcache \
curl \
gd \
mysqli \
exif \
mbstring \
pdo \
pdo_pgsql \
pdo_mysql \
pdo_sqlite \
pspell \
pgsql \
soap \
zip \
&& docker-php-ext-configure zip --with-libzip \
&& docker-php-ext-install zip
# PECL modules
RUN pecl install imagick \
&& pecl install xdebug-2.6.0
COPY ./xdebug/xdebug.ini /usr/local/etc/php/conf.d/
# Enable PECL modules
RUN docker-php-ext-enable imagick xdebug
# cleanup apt
RUN apt-get clean
RUN apt-get autoremove -y
# enable apache modules
RUN a2enmod rewrite headers cache cache_disk expires vhost_alias userdir autoindex
RUN service apache2 restart
RUN service apache-htcacheclean start
RUN usermod -u 1000 www-data
RUN usermod -G staff www-data
RUN chown -R www-data:www-data /var/www
RUN echo "memory_limit=-1" > "$PHP_INI_DIR/conf.d/memory-limit.ini" \
&& echo "date.timezone=${PHP_TIMEZONE:-UTC}" > "$PHP_INI_DIR/conf.d/date_timezone.ini"
RUN apk add --no-cache --virtual .build-deps zlib-dev libzip-dev \
&& docker-php-ext-configure zip --with-libzip \
&& docker-php-ext-install zip \
&& runDeps="$( \
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local/lib/php/extensions \
| tr ',' '\n' \
| sort -u \
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
)" \
&& apk add --virtual .composer-phpext-rundeps $runDeps \
&& apk del .build-deps
ENV COMPOSER_ALLOW_SUPERUSER 1
ENV COMPOSER_HOME /tmp
ENV COMPOSER_VERSION 1.8.0
RUN curl --silent --fail --location --retry 3 --output /tmp/installer.php --url https://raw.githubusercontent.com/composer/getcomposer.org/b107d959a5924af895807021fcef4ffec5a76aa9/web/installer \
&& php -r " \
\$signature = '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061'; \
\$hash = hash('SHA384', file_get_contents('/tmp/installer.php')); \
if (!hash_equals(\$signature, \$hash)) { \
unlink('/tmp/installer.php'); \
echo 'Integrity check failed, installer is either corrupt or worse.' . PHP_EOL; \
exit(1); \
}" \
&& php /tmp/installer.php --no-ansi --install-dir=/usr/bin --filename=composer --version=${COMPOSER_VERSION} \
&& composer --ansi --version --no-interaction \
&& rm -rf /tmp/* /tmp/.htaccess
RUN chmod 700 /usr/bin/composer
COPY docker-entrypoint.sh /docker-entrypoint.sh
WORKDIR /var/www
CMD ["apache2-foreground"]
EXPOSE 80
docker-entrypoint.sh has the following code (from official composer docker page):
#!/usr/bin/env bash
isCommand() {
for cmd in \
"about" \
"archive" \
"browse" \
"check-platform-reqs" \
"clear-cache" \
"clearcache" \
"config" \
"create-project" \
"depends" \
"diagnose" \
"dump-autoload" \
"dumpautoload" \
"exec" \
"global" \
"help" \
"home" \
"info" \
"init" \
"install" \
"licenses" \
"list" \
"outdated" \
"prohibits" \
"remove" \
"require" \
"run-script" \
"search" \
"self-update" \
"selfupdate" \
"show" \
"status" \
"suggests" \
"update" \
"upgrade" \
"validate" \
"why" \
"why-not"
do
if [ -z "${cmd#"$1"}" ]; then
return 0
fi
done
return 1
}
# check if the first argument passed in looks like a flag
if [ "$(printf %c "$1")" = '-' ]; then
set -- /sbin/tini -- composer "$#"
# check if the first argument passed in is composer
elif [ "$1" = 'composer' ]; then
set -- /sbin/tini -- "$#"
# check if the first argument passed in matches a known command
elif isCommand "$1"; then
set -- /sbin/tini -- composer "$#"
fi
exec "$#"
docker-compose.yml has the following code:
version: '3'
services:
php:
container_name: local_php
build: .
image: php:7.2.13-apache
ports:
- "80:80"
- "443:443"
- "9001:9001"
volumes:
- ../:/var/www/html/
I expect to be able to run composer commands from the terminal (e.g. composer install) but I get the error -bash: composer: command not found each time I try to run any composer command after doing a Dockerfile build.
I finally figured it out; in case someone's trying to achieve the same you got two options basically:
Access php container bash (by using docker exec -it <container name> /bin/bash and navigate to the folder you wish to use composer on, and run composer commands. It might also be helpful to note that docker-compose run <container name> ls would show container's mounted volumes (if you wish to check / make sure).
Run the following commands in macos terminal, to be able to use composer as if it was installed locally:
#!/bin/bash
mkdir ~/.functions
echo '#!/bin/bash
tty=
tty -s && tty=--tty
docker run \
$tty \
--interactive \
--rm \
--user $(id -u):$(id -g) \
--workdir /var/www/html/${PWD##*/} \
--volume /etc/passwd:/etc/passwd:ro \
--volume /etc/group:/etc/group:ro \
--volume $(pwd):/var/www/html/${PWD##*/} \
composer "$#"' > ~/.functions/composer
echo 'alias composer="sh ~/.functions/composer"' >> ~/.bash_profile
source ~/.bash_profile
Then in terminal try composer version to see if it's working; if not, try executing source ~/.bash_profile once more, and re-try.
Hope that helps!
I have an symfony application, and i want to create docker container, that contains all needed files. The purpose is to spin up/down containers for scaling, without any other deploying processes. Just with given DB connection.
Building means, pretty much just git clone and running composer install, but some of symfony's post install scripts fail without configured DB.
Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache
Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installAssets
Can i not run these scripts when i'm building container? Or what the proper way to do symfony deployment?
Using Symfony 3.2, Doctrine2, PHP 7.1
The proper way to build a container without running the db script is by not running there scripts in the build,
Here is the one we use in production for api-platform:
FROM php:7.1-fpm-alpine
RUN apk add --no-cache --virtual .persistent-deps \
git \
icu-libs \
zlib \
postgresql-client
ENV APCU_VERSION 5.1.8
RUN set -xe \
&& apk add --no-cache --virtual .build-deps \
$PHPIZE_DEPS \
icu-dev \
zlib-dev \
postgresql-dev \
sqlite-dev \
pcre-dev \
&& docker-php-ext-install \
intl \
mbstring \
pdo_mysql \
pdo_pgsql \
pdo \
pgsql \
zip \
pdo_sqlite \
&& pecl install \
apcu-${APCU_VERSION} \
&& docker-php-ext-enable --ini-name 20-apcu.ini apcu \
&& docker-php-ext-enable --ini-name 05-opcache.ini opcache \
&& apk del .build-deps
COPY docker/php/php.ini /usr/local/etc/php/php.ini
COPY docker/php/install-composer.sh /usr/local/bin/docker-app-install-composer
RUN chmod +x /usr/local/bin/docker-app-install-composer
RUN set -xe \
&& apk add --no-cache --virtual .fetch-deps \
openssl \
&& docker-app-install-composer \
&& mv composer.phar /usr/local/bin/composer \
&& apk del .fetch-deps
ARG SYMFONY_ENV=dev
ENV SYMFONY_ENV=dev
RUN if [ "$SYMFONY_ENV" -ne "dev" ]; then \
sed -i '1 a xdebug.remote_enable=1' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
sed -i '1 a xdebug.remote_handler=dbgp' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
sed -i '1 a xdebug.remote_autostart=0' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
sed -i '1 a xdebug.remote_connect_back=1 ' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
sed -i '1 a xdebug.remote_port=9001' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
sed -i '1 a xdebug.remote_log=/var/log/xdebug_remote.log' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
pecl install \
xdebug \
&& docker-php-ext-enable xdebug; \
fi;
# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
ENV COMPOSER_ALLOW_SUPERUSER 1
WORKDIR /srv/quotatis
COPY composer.json ./
COPY composer.lock ./
RUN mkdir -p \
var/cache \
var/logs \
var/sessions \
&& composer global require "hirak/prestissimo:^0.3" --prefer-dist --no-progress --no-suggest -o -a \
&& composer install --prefer-dist --no-dev --no-autoloader --no-scripts --no-progress --no-suggest \
&& composer clear-cache \
# Permissions hack because setfacl does not work on Mac and Windows
&& chown -R www-data var
COPY app app/
COPY bin bin/
COPY src src/
COPY web web/
COPY etc etc/
RUN composer dump-autoload --optimize --classmap-authoritative --no-dev
COPY docker/php/start.sh /usr/local/bin/docker-app-start
RUN chmod +x /usr/local/bin/docker-app-start
CMD ["docker-app-start"]
You could see the whole stack (nginx + fpm + varnish on github)
The line that you need in here is this one
composer install --prefer-dist --no-dev --no-autoloader --no-scripts --no-progress --no-suggest