php: docker-php-ext-install fails but returns 0
There is one quite annoying thing with current docker-php-ext-install.
It runs extensions sources compilation in subshell docker-php-ext-install:93-104. So if compilation of some extension fails, the set -e has no effect on it and docker-php-ext-install continues to execute.
This lead to very bad situations when docker build succeeds, but in fact extensions are not installed.
Issue can be easily reproduced with the following Dockerfile:
FROM php:alpine
RUN docker-php-ext-install \
gd \
opcache
It builds successfully. However, if we php -i inside built container, there is no gd extension installed. Why? 'Cause docker-php-ext-install gd’s dependencies where not satisfied (libpng, libjpeg, etc.) and docker build log confirms it with following lines:
checking for FreeType 2... no
checking whether to enable truetype string function in GD... no
checking whether to enable JIS-mapped Japanese font support in GD... no
configure: error: png.h not found.
If we remove that subshell execution:
FROM php:alpine
RUN sed -i -r 's/^\t+\($//g' /usr/local/bin/docker-php-ext-install \
&& sed -i -r 's/^\t+\)$//g' /usr/local/bin/docker-php-ext-install
RUN docker-php-ext-install \
gd \
opcache
The docker build fails at compiling gd step as expected.
Is that subshell really required there?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 15 (10 by maintainers)
@SG5, that is normal behavior; the
docker-php-*scripts do not install any run dependencies. You need to install any dependencies that gd may require like the example in the docs for the Debian based image. It should be a similar setup for the Alpine based image.For example, if we make the following change to
docker-php-ext-configure, thendocker-php-ext-install /some/absolute/pathwill also be acceptable usage of this script (which was previously acceptable IIRC, but got lost in a refactoring somewhere):Wow, wow, wow! Something interesting was found here!
First of all, I’m sorry for providing “buggy” PoC, which lead to wrong conclusions. Actually there is no sense of
opcacheext there. But the issue I’ve pointed to still remains.Having
Dockerfilelike:We have next successful result of
docker build(you may just check it):While if we are using
sedto remove subshell:Build fails as expected at
configurestep:And now is interesting…
I didn’t know about
-einheritance. And reproduced your example in my macOS terminal:It really works. But why those
Dockerfiles behave so?That’s why:
@tyranron I was about to look at how to solve this and make a PR when I found this issue. I guess you should make a PR 😃
just to avoid changing for working directory for the rest of the script (even if there is not much going on after that)