Reputation: 1048
I'm using this offical php Docker image: https://github.com/docker-library/php/blob/76a1c5ca161f1ed6aafb2c2d26f83ec17360bc68/7.1/alpine/Dockerfile
Now I need to add support for yaml extension, that is not bundled with php. I see the base image I'm using uses phpize.
I'm trying with this approach:
FROM php:7.1.5-alpine
# Install and enable yaml extension support to php
RUN apk add --update yaml yaml-dev
RUN pecl channel-update pecl.php.net
RUN pecl install yaml-2.0.0 && docker-php-ext-enable yaml
But I get this errors:
running: phpize
Configuring for:
PHP Api Version: 20160303
Zend Module Api No: 20160303
Zend Extension Api No: 320160303
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.
ERROR: `phpize' failed
ERROR: Service 'php_env' failed to build: The command '/bin/sh -c pecl install yaml-2.0.0 && docker-php-ext-enable yaml' returned a non-zero code: 1
What is the most idiomatic docker way to use that image and add that support?
Should I use it as base, or is someway possible to add parameters in order to make wanted extension configurable?
Upvotes: 4
Views: 9162
Reputation: 1769
Alpine uses apk to install packages. The compiling process is complaining about missing autoconf
, which is found in Alpine's autoconf
package.
I'd suggest you to run these commands:
RUN apk --update yaml-dev
RUN apk add --no-cache --virtual .build-deps \
g++ make autoconf
RUN pecl channel-update pecl.php.net
RUN pecl install yaml && docker-php-ext-enable yaml
RUN apk del --purge .build-deps
If you need to install other non-dev libraries, you can install them in a separate apk add
command. This procedure will:
install the build deps, using --no-cache
means you're using an updated index and not cached locally (thus no need of --update
or to save the pkg in the cache). --virtual
means you're creating a virtual reference for all those packages that can later be deleted (because they're useless after the compiling process)
do your stuff with pecl and docker-php-ext-enable
delete the previous build deps
If you still encounter any missing dependency, you can see as reference this: https://pkgs.alpinelinux.org/packages
Upvotes: 9
Reputation: 1002
The latest version, at least since 2.0.4, requires yaml-dev to be installed in order to run. So move that to the packages you want to keep in the image. Also, on alpine 3.11 in combination of php-alpine repository, I got the problem that it wants you to add the location of your php.ini file.
just add the following: RUN pear config-set php_ini /etc/php7/php.ini
where you change the path into the path of the location of your php.ini if needed.
Upvotes: 0