Docker and command docker-php - php

Following my previous post.
I managed to install oci8-2.2.0 via pecl.
Now I have a problem, I cannot launch the commands:
docker-php-ext- *
It always gives me an error:
/ bin / sh: 1: docker-php-ext-configure: not found
In my Dockerfile :
FROM ubuntu:latest
COPY --from=library/docker:latest /usr/local/bin/docker /usr/bin/docker
COPY --from=docker/compose:latest /usr/local/bin/docker-compose /usr/bin/docker-compose
I install my necessary packages:
RUN apt-get install -y \
apache2 \
libapache2-mod-php \
libldap2-dev \
vim \
curl \
git \
openssl \
bash \
mysql-client \
g++ \
gcc \
make \
libaio1 \
wget \
unzip \
libapache2-mod-php7.4 \
software-properties-common \
systemtap-sdt-dev \
build-essential \
libcurl4-gnutls-dev \
unixodbc-dev \
net-tools
I install the PHP dependencies:
RUN apt-add-repository -y ppa:ondrej/php
RUN apt-get update
RUN apt-get install -y \
php7.4 \
php7.4-fpm \
php7.4-xml \
php-common \
php7.4-gd \
php7.4-mbstring \
php7.4-gd \
php7.4-iconv \
php7.4-pdo \
php7.4-tokenizer \
php7.4-mysql \
php-ldap \
php7.4-ldap \
php7.4-fileinfo \
php7.4-simplexml \
php7.4-xmlwriter \
php7.4-zip \
php7.4-json \
php-dev \
php-pear
Finally, the commands are launched after installing Oracle Instant Client:
# Oracle instantclient
RUN export PHP_DTRACE=yes
ADD instantclient-basic-linux.x64-12.2.0.1.0.zip /tmp/
ADD instantclient-sdk-linux.x64-12.2.0.1.0.zip /tmp/
RUN unzip /tmp/instantclient-basic-linux.x64-12.2.0.1.0.zip -d /usr/local/
RUN unzip /tmp/instantclient-sdk-linux.x64-12.2.0.1.0.zip -d /usr/local/
RUN mv /usr/local/instantclient_12_2 /usr/local/instantclient
RUN ln -s /usr/local/instantclient/libclntsh.so.12.1 /usr/local/instantclient/libclntsh.so
RUN ln -s /usr/local/instantclient/libocci.so.12.1 /usr/local/instantclient/libocci.so
ENV LD_LIBRARY_PATH=/usr/local/instantclient
RUN echo "instantclient,/usr/local/instantclient"| pecl install oci8-2.2.0
RUN docker-php-ext-configure pdo_oci --with-pdo-oci=instantclient,/usr/local/instantclient
RUN docker-php-ext-install pdo_oci
RUN docker-php-ext-enable oci8-2.2.0
Any idea for Docker to find docker-php-ext- commands?
BR

Commands docker-php-ext- * are helper scripts provided by PHP images. But you are using ubuntu:latest image, which is doesn't contain them.
You can use scripts from php image for example that one. But I think it is easier to use php docker images.

Related

How i can install snmp-module in php on Dokerfile

My problem: When i run command
docker build --no-cache -t php --progress=plain .
My container is building, but I get Error in my PHP-project:
Error Call to undefined function snmp2_real_walk()
Command install in Dockerfile is't work... I need help!!
My Dockerfile:
FROM php:7.4-apache
# Use the default production configuration
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
RUN if command -v a2enmod >/dev/null 2>&1; then \
a2enmod rewrite headers \
;fi
RUN apt-get update
# Install tools required for build stage
RUN apt-get install -fyqq \
bash curl wget rsync ca-certificates openssl ssh git tzdata openntpd \
libxrender1 fontconfig libc6 \
mariadb-client gnupg binutils-gold autoconf \
g++ gcc gnupg libgcc1 linux-headers-amd64 make python
#RUN apt install -y libsnmp-dev
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer \
&& chmod 755 /usr/bin/composer
# Install additional PHP libraries
RUN docker-php-ext-install bcmath pdo_mysql
RUN \
apt-get update && \
apt-get install libldap2-dev -y && \
rm -rf /var/lib/apt/lists/* && \
docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/ && \
docker-php-ext-install ldap
# Install libraries for compiling GD, then build it
RUN apt-get update && apt-get install -y \
libfreetype6 \
libfreetype6-dev \
libjpeg62-turbo \
libjpeg62-turbo-dev \
libsqlite3-dev \
libssl-dev \
libpng-dev \
libpng16-16 \
libcurl3-dev \
libxml2-dev \
libonig-dev \
libsnmp-dev \
snmp \
&& docker-php-ext-install mysqli xmlrpc \
&& docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ \
&& docker-php-ext-install gd \
&& apt-get remove -fyqq libfreetype6-dev libpng-dev libjpeg62-turbo-dev
# -------------------- Installing PHP Extension: snmp --------------------
RUN docker-php-ext-configure snmp --with-snmp \
# Installation
&& docker-php-ext-install -j$(getconf _NPROCESSORS_ONLN) snmp \
&& true
RUN sed -i 's/;extension=snmp/extension=snmp/' php.ini-production
# Add ZIP archives support
RUN apt-get install -fyqq zip libzip-dev \
&& docker-php-ext-install zip \
&& apt-get remove -fyqq libzip-dev
# Install xdebug
RUN pecl install xdebug \
&& docker-php-ext-enable xdebug
# Enable XDebug
ADD xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini
WORKDIR /app
I've tried a lot of options. Editing the
php.ini-production
file did not lead to the expected result. At the same time, the php.ini file also does not exist, but the command is present...

Call to undefined function imagewebp (Dockerfile, php, gd, webp)

I'm not able to enable webp support inside a docker container. ¿What am I missing in Dockerfile configuration?
When execute a php script I get this error:
Fatal error: Uncaught Error: Call to undefined function imagewebp()....
Executing php -i to see if gd is enabled:
root#a5e8fec22e8b:/var/www/html# php -i | grep -ia gd
Additional .ini files parsed => /usr/local/etc/php/conf.d/docker-php-ext-gd.ini,
gd
GD Support => enabled <--------- GD is enabled
GD Version => bundled (2.1.0 compatible)
gd.jpeg_ignore_warning => 1 => 1
php gd_info output:
"GD Version":"bundled (2.1.0 compatible)",
"FreeType Support":true,
"FreeType Linkage":"with freetype",
"GIF Read Support":true,
"GIF Create Support":true,
"JPEG Support":true,
"PNG Support":true,"WBMP Support":true,
"XPM Support":false,
"XBM Support":true,
"WebP Support":false, <----------------------------- :?
"BMP Support":true,
"JIS-mapped Japanese Font Support":false
Dockerfile
FROM php:7.2-apache
COPY ./apache2/sites-available/*.conf /etc/apache2/sites-available/
RUN apt-get update && apt-get install --no-install-recommends -y \
wget \
nano \
git \
unzip \
iputils-ping
# Install PHP extensions deps
RUN apt-get update \
&& apt-get install --no-install-recommends -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libjpeg-dev \
libwebp-dev \
libpng-dev \
libmcrypt-dev \
zlib1g-dev \
libicu-dev \
g++ \
unixodbc-dev \
libxml2-dev \
libaio-dev \
libmemcached-dev \
freetds-dev \
libssl-dev \
openssl \
libsodium-dev
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- \
--install-dir=/usr/local/bin \
--filename=composer
# Install PHP extensions
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-webp-dir=/usr/include/ \
&& docker-php-ext-configure pdo_dblib --with-libdir=/lib/x86_64-linux-gnu \
&& pecl install sqlsrv-4.1.6.1 \
&& pecl install pdo_sqlsrv-4.1.6.1 \
&& pecl install redis \
&& pecl install memcached \
&& pecl install -f libsodium \
&& docker-php-ext-install \
iconv \
mbstring \
intl \
gd \
mysqli \
pdo_mysql \
pdo_dblib \
soap \
sockets \
sodium \
zip \
pcntl \
ftp \
&& docker-php-ext-enable \
sqlsrv \
pdo_sqlsrv \
redis \
memcached \
opcache \
gd \
sodium
RUN a2enmod rewrite negotiation
RUN mkdir /home/laravel && \
chown -R www-data:www-data /home/laravel
RUN chown -R www-data:www-data /var/www
RUN service apache2 restart
I tested a simple Dockerfile based on an example copied from this repository.
My Dockerfile looks like this:
FROM php:7.2-apache
ADD https://raw.githubusercontent.com/mlocati/docker-php-extension-installer/master/install-php-extensions /usr/local/bin/
RUN chmod uga+x /usr/local/bin/install-php-extensions && sync && \
install-php-extensions gd
COPY index.php /var/www/html/
Before building, I create a php file, index.php, to copy to my new image.
<?php
phpinfo();
?>
Then, I build and run my new image with these commands:
docker build -t php7-with-gd -f Dockerfile .
docker run -d --rm -p 88:80 --name test-phpgd php7-with-gd
And my output page with the PHP information looks like this.

Install debian stretch with php5.6

We are using laravel based on php version 5.6, few days ago Debian removed jessie version (8) so we need to upgrade that to 9, but the issue is its hard to use Debian 9 without php5.6 as scripts like
docker-php-ext-install
does not seem to work there. i attach my section of the installation in the docker-file. Would appreciate if there is a solution to this
I have tried to install the pdo_mysql without the docker-php-ext-install
but it fails cannot locate that..
FROM debian:9.0
RUN apt-get update \
&& apt-get -y install \
apt-transport-https apt-utils \
lsb-release \
ca-certificates \
wget \
mcrypt \
libmcrypt-dev \
git-core \
unzip \
&& wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg \
&& echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list \
&& apt-get update \
&& apt-get -y install gnupg2 php5.6-cli php5.6-fpm \
&& apt-get update \
&& docker-php-ext-install \
mbstring \
pdo_mysql \
mcrypt bcmath\
&& update-alternatives --install /usr/bin/php php /usr/bin/php5.6 90 \
&& update-alternatives --set php /usr/bin/php5.6
And this is the end of the build call :
Reading package lists...
/bin/sh: 1: docker-php-ext-install: not found
docker-php-ext-install is a command provided by official php images. You will find it only on those images or images based on those.
Official docker php images providing php 5.6 still exist on the docker hub:
wget -qO- https://registry.hub.docker.com/v1/repositories/php/tags | jq '.[].name' | grep -P '^"5\.6(?!\.)'
"5.6"
"5.6-alpine"
"5.6-alpine3.4"
"5.6-alpine3.7"
"5.6-alpine3.8"
"5.6-apache"
"5.6-apache-jessie"
"5.6-apache-stretch"
"5.6-cli"
"5.6-cli-alpine"
"5.6-cli-alpine3.4"
"5.6-cli-alpine3.7"
"5.6-cli-alpine3.8"
"5.6-cli-jessie"
"5.6-cli-stretch"
"5.6-fpm"
"5.6-fpm-alpine"
"5.6-fpm-alpine3.4"
"5.6-fpm-alpine3.7"
"5.6-fpm-alpine3.8"
"5.6-fpm-jessie"
"5.6-fpm-stretch"
"5.6-jessie"
"5.6-stretch"
"5.6-zts"
"5.6-zts-alpine"
"5.6-zts-alpine3.4"
"5.6-zts-alpine3.7"
"5.6-zts-alpine3.8"
"5.6-zts-jessie"
"5.6-zts-stretch"
Furthermore, those images are built on top of debian 9:
docker run --rm php:5.6 cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
and provide the docker-php-ext-install command:
docker run --rm php:5.6 which docker-php-ext-install
/usr/local/bin/docker-php-ext-install
I suggest you use one of those official image as the base for your Dockerfile.
FROM php:5.6-fpm
RUN apt-get update \
&& apt-get -y install \
libmcrypt-dev \
mcrypt \
&& docker-php-ext-install \
bcmath \
mbstring \
mcrypt \
pdo_mysql

How To Install PHP Composer via Docker And Use As If It Was Installed Locally?

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!

Docker with wkhtmltopdf is not work correctly

I am trying to use wkhtmltopdf in a container with Docker and Symfony.
The installation is done well, but the result is very different from the reality, so I think some libraries must be missing in the system, but I don't know which one.
I've been checking other questions here and in google, but they don't help.
FROM phpdockerio/php71-fpm:latest
# Fix debconf warnings upon build
ARG DEBIAN_FRONTEND=noninteractive
# Install selected extensions and other stuff
RUN apt-get update \
&& apt-get -y --no-install-recommends install cron \
php7.1-mysql \
php-redis \
php7.1-bcmath \
php7.1-gd \
php-imagick \
php7.1-intl \
cron \
python \
xz-utils \
libxrender1 \
libfontconfig1 \
zlib1g \
fontconfig \
libfreetype6 \
libx11-6 \
libxext6 \
wkhtmltopdf
RUN curl --insecure https://getcomposer.org/composer.phar -o /usr/bin/composer && chmod +x /usr/bin/composer
RUN cd /tmp \
&& curl "https://downloads.wkhtmltopdf.org/0.12/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz" -L -o "wkhtmltopdf.tar.xz" \
&& tar Jxvf wkhtmltopdf.tar.xz \
&& rm wkhtmltopdf.tar.xz \
&& mv wkhtmltox/include/* /usr/local/include/ \
&& mv wkhtmltox/lib/* /usr/local/lib/ \
&& mv wkhtmltox/bin/* /usr/local/bin/ \
&& mv wkhtmltox/share/* /usr/local/share/
RUN apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
CMD php-fpm -F
This is the result in the container(docker)
And this is the result on my machine (without docker), as it should be.
Any idea what might be happening?

Categories