I am using the official php:fpm docker image as base for my application container, so the Dockerfile starts like so:
FROM php:fpm
Later in the file I would like to have something like that:
RUN apt-get install -y \
php7.0-gd
But that tells me:
E: Unable to locate package php7.0-gd
E: Couldn't find any package by regex 'php7.0-gd'
»Bashing« into the container using docker exec -it <name> /bin/bash and executing: apt-cache search php | grep gd yields:
php5-gdcm - Grassroots DICOM PHP5 bindings
php5-vtkgdcm - Grassroots DICOM VTK PHP bindings
php5-gd - GD module for php5
So since that is a debian (yessie) based image, only the old php5 packages are available and php7 is installed by some tricky script in the php:fpm dockerfile and it seams that all extensions are compiled within the used php executable.
How can I install more extensions in this scenario?
Quoting https://hub.docker.com/_/php/
How to install more PHP extensions
We provide the helper scripts docker-php-ext-configure, docker-php-ext-install, and docker-php-ext-enable to more easily install PHP extensions.
To install PHP with iconv, mcrypt and GD, they provide the following example:
FROM php:7.0-fpm
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng-dev \
&& 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
Please refer to the Dockerhub page for more details.
Related
I have run into a strange problem where bcmath PHP extension doesn't get installed in Dockerfile but later if I go into my container then I can install it manually. But the problem is if I restart the container all changes are lost.
My Dockerfile
FROM php:7.2-fpm
WORKDIR /var/www
RUN apt-get update && apt-get install -y \
build-essential \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
git \
curl
RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl
RUN docker-php-ext-configure gd --with-gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/
RUN docker-php-ext-install gd
RUN docker-php-ext-install bcmath
EXPOSE 9000
CMD ["php-fpm"]
By the output of php -m I see that bcmath extension did not get installed.
But I can install it manually like this
$ docker-compose exec php bash
$ docker-php-ext-install bcmath
$ kill -s USR2 1
Now bcmath extension is installed and works. But when I restart the container it's gone again. Why didn't it install it from Dockerfile I don't understand... What am I doing wrong?
I finally found the problem so I'll share with others. I removed all containers and all images and re-built everything and now everything installed correctly. So the solution was to rebuild the PHP image.
I an trying to create a dockerized network for my application. With my current docker-compose.yml configuration I am able to get everything up and running and working. The issue I am facing is when I am trying to install composer packages dependant on the GD extension. Can anyone tell me what is wrong with either my Dockerfile for PHP or my docker-compose network setup?
PHP Dockerfile
FROM php:7.3-alpine
# Install php extensions
RUN apk update && apk add --no-cache postgresql-dev && apk add libzip-dev freetype-dev libjpeg-turbo-dev libpng-dev
RUN docker-php-ext-install pdo pdo_pgsql mbstring zip
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install gd
# Setup working directory
WORKDIR /var/www/html
Docker Compose PHP Network Block
php:
build:
context: .
dockerfile: Dockerfile
container_name: ${PROJECT_NAME}-php
volumes:
- ./src:/var/www/html
ports:
- "9001:9000"
networks:
- testNetwork
Thanks in advance!!
Continued: When I shell into the running docker container, you can see the loaded docker-php-extensions.
/usr/local/etc/php/conf.d # ls
docker-php-ext-gd.ini docker-php-ext-pdo_pgsql.ini docker-php-ext-sodium.ini docker-php-ext-zip.ini
/usr/local/etc/php/conf.d #
Easiest way to do so, is this awesome project on github, easily replace:
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/bin/
RUN install-php-extensions gd
with your Dockerfile's php extension installation section.
Edit:
You can also install composer on any docker container as easy as pasting:
COPY --from=composer /usr/bin/composer /usr/bin/composer
RUN apt-get install -y openssl zip unzip git libonig-dev libxml2-dev libpng-dev libjpeg-dev libfreetype6-dev libonig-dev curl mcrypt gnupg build-essential software-properties-common wget vim libwebp-dev
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-webp-dir=/usr/include/ --with-jpeg-dir=/usr/include
RUN docker-php-ext-install mysqli mbstring pdo pdo_mysql tokenizer xml bcmath opcache pcntl intl soap exif gd
Try with above code snippet, for gd there are php-ext-configure install and install some lib like libpng-dev
Hope it will helpful for you
I'm new to Docker and I'm trying to install PHP GD extension.
This is my current Dockerfile:
FROM php:7.4-fpm-alpine
RUN docker-php-ext-install mysqli pdo pdo_mysql bcmath gd
When running the docker via docker-compose build && docker-compose up -d I'm getting a lots of errors and in the end I get this message:
configure: error: Package requirements (zlib) were not met:
Package 'zlib', required by 'virtual:world', not found
Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.
Alternatively, you may set the environment variables ZLIB_CFLAGS
and ZLIB_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
ERROR: Service 'php' failed to build: The command '/bin/sh -c docker-php-ext-install mysqli pdo pdo_mysql bcmath gd' returned a non-zero code: 1
Without the "gd" at the end the Docker container runs normally.
What could be the problem and how could I fix it?
You can try to add these settings in Dockerfile:
FROM php:7.4-fpm
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd
Official documentation. Hope it's help you.
In my docker using PHP8.0 I got GD working for jpg,png and webp by adding the following lines to my php.dockerfile:
FROM php:8.0-fpm-alpine
# Install dependencies for GD and install GD with support for jpeg, png webp and freetype
# Info about installing GD in PHP https://www.php.net/manual/en/image.installation.php
RUN apk add --no-cache \
libjpeg-turbo-dev \
libpng-dev \
libwebp-dev \
freetype-dev
# As of PHP 7.4 we don't need to add --with-png
RUN docker-php-ext-configure gd --with-jpeg --with-webp --with-freetype
RUN docker-php-ext-install gd
One more way to approach the issue is to use install-php-extensions in Dockerfile:
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN chmod +x /usr/local/bin/install-php-extensions && sync && \
install-php-extensions gd xdebug
Works in Alpine and PHP8.
Docs here
If someone has problems installing php-gd extension in Docker, look up to #Dmitry comment or Documentation and search for "PHP Core Extensions".
You can see full code on my Github, if you want to see how am I running my NGINX and PHP with php-gd extension.
I'm trying to use phpdocx in order to create a docx file from HTML in a laravel api application.
In order to use this conversion tool, it is necessary to have Tidy installed.
I've included tidy in dockerfile like so
FROM php:7.2-fpm-stretch
RUN apt-get update && \
apt-get install -y --no-install-recommends \
libicu-dev \
openssh-client\
git \
curl \
libmemcached-dev \
libz-dev \
libpq-dev \
libjpeg-dev \
libpng-dev \
tidy \
libfreetype6-dev \
libssl-dev \
libmcrypt-dev \
gnupg \
&& rm -rf /var/lib/apt/lists/*
but when I add a phpinfo(); to my code, tidy is no where to be found.
What is strange is that when I access the bash of docker, I can tidy -v and i get HTML Tidy for Linux version 5.2.0
I have uncommented extension=php_tidy.dll in all the php.ini files associated with the project, and have rebuilt the image numerous times.
When I run check.php included in phpdocx I can find this error in the result Warning You must install Tidy for PHP if you want to use embedHTML in your Word documents.
I've tried docker pull imega/tidy to no avail.
I've been stuck on this for over a day now, if anyone has any idea where I'm going wrong I would appreciate the help.
root#c790d433727a:/var/www/vendor/phpdocx# php check.php
OK PHP version is 7.2.22
OK Zip support is enabled.
OK DOM support is enabled.
OK XML support is enabled.
Warning You must install Tidy for PHP if you want to use embedHTML in your Word documents.
OK mbstring is enabled.
root#c790d433727a:/var/www/vendor/phpdocx# tidy -v
HTML Tidy for Linux version 5.2.0
See an example Docker file:
FROM php:7.2-fpm-stretch
RUN apt-get -y update && apt-get -y upgrade
RUN apt-get install -y libtidy-dev
RUN docker-php-ext-install -j$(nproc) tidy
if you build it this way:
docker build --tag stackoverflow .
and run this way:
docker run --rm -it --entrypoint="" stackoverflow /bin/sh
you will be logged into CLI and may check installed extensions this way:
php -m
that gives list:
[PHP Modules]
Core
ctype
curl
date
dom
fileinfo
filter
ftp
hash
iconv
json
libxml
mbstring
mysqlnd
openssl
pcre
PDO
pdo_sqlite
Phar
posix
readline
Reflection
session
SimpleXML
sodium
SPL
sqlite3
standard
tidy
tokenizer
xml
xmlreader
xmlwriter
zlib
[Zend Modules]
with:
tidy
under:
[PHP Modules]
Have fun with it :)
I faced the same problem few days ago, problem was not only tidy library self but missed other tidy dependency libtidy-dev, this works perfectly to install and load tidy:
# Install system dependencies
RUN apt-get update && apt-get install -y \
nano \
libxml2-dev \
libzip-dev \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
libmagickwand-dev \
**libtidy-dev** \
git \
curl \
zip \
ssh\
wget\
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install \
exif \
gd \
soap \
zip
RUN docker-php-ext-install tidy \
&& docker-php-ext-enable tidy
Because I want PHP 7.3 features I am trying to update the project from PHP 7.2 to PHP 7.3. Within docker-compose.yml I have:
php:
build: ./docker/php
volumes:
- .:/var/www/html
links:
- mysql:mysql
depends_on:
- mysql
networks:
- pimcorenet
My Dockerfile is like:
FROM php:7.2-fpm
# install git
RUN apt-get update && \
apt-get install -y --no-install-recommends git
#install some base extensions
RUN apt-get install -y \
zlib1g-dev \
zip \
libpng-dev \
exiftool \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libicu-dev \
libpq-dev \
libxpm-dev \
libvpx-dev \
mariadb-client \
libxml2-dev
RUN docker-php-ext-install -j$(nproc) \
zip \
exif \
bcmath \
intl \
pcntl \
mysqli \
pdo \
gd \
pdo_mysql \
pdo_pgsql \
mbstring \
soap \
opcache \
iconv
# Install Imagick
RUN apt-get update && apt-get install -y \
libmagickwand-dev --no-install-recommends \
&& pecl install imagick \
&& docker-php-ext-enable imagick
# Install Composer
RUN echo "Install Composer"
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN composer --version
I am getting the following error:
E: Failed to fetch
http://cdn-fastly.deb.debian.org/debian/pool/main/r/readline/readline-common_7.0-5_all.deb
Could not resolve 'cdn-fastly.deb.debian.org' E: Failed to fetch
http://cdn-fastly.deb.debian.org/debian/pool/main/j/jquery/libjs-jquery_3.3.1~dfsg-3_all.deb
Could not resolve 'cdn-fastly.deb.debian.org' E: Failed to fetch
http://cdn-fastly.deb.debian.org/debian/pool/main/f/freetype/freetype2-doc_2.9.1-3_all.deb
Could not resolve 'cdn-fastly.deb.debian.org' E: Failed to fetch
http://cdn-fastly.deb.debian.org/debian/pool/main/i/icu/icu-devtools_63.1-6_amd64.deb
Could not resolve 'cdn-fastly.deb.debian.org' E: Failed to fetch
http://cdn-fastly.deb.debian.org/debian/pool/main/j/javascript-common/javascript-common_11_all.deb
Could not resolve 'cdn-fastly.deb.debian.org' ..... more errors
ERROR: Service 'php' failed to build: The command '/bin/sh -c apt-get
install -y zlib1g-dev zip libpng-dev
exiftool libfreetype6-dev libjpeg62-turbo-dev
libmcrypt-dev libicu-dev libpq-dev libxpm-dev
libvpx-dev mariadb-client libxml2-dev' returned a
non-zero code: 100
What is the exact problem with this? Is it because some required PHP extensions are not yet available for PHP 7.3 or have been replaced? How do I resolve this? Just changed FROM php:7.2-fpm to FROM php:7.3-fpm.
You are failing to grok containers. And because of that you are taking the wrong approach.
You shouldn't be trying to 'upgrade' a php 7.2 to container to 7.3.
You should be creating a new container image that is based off 7.3 to begin with.
Incidentally, I would recommend making it me a new, separate service to your existing 7.2 container, i.e. a new Dockerfile, rather than just changing the existing container/Dockerfile. That will allow you to test the two versions alongside each other, rather than having a 'leap of faith' change over.
Also, I'd recommend building off the Debian or Ubuntu images directly, rather than going through the 'official' Docker images. They are only official in the sense of being made by Docker, but they are not quite as well supported in my opinion.
This is the dockerfile I'm using currently: https://github.com/Danack/example/blob/master/docker/php_fpm/Dockerfile Switching 7.2 to 7.3 should 'just work'.