使用官方的 Alpine Docker 镜像将 yaml 扩展添加到 php [英] add yaml extension to php on using official Alpine Docker image

查看:42
本文介绍了使用官方的 Alpine Docker 镜像将 yaml 扩展添加到 php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用这个官方的 php Docker 镜像:https://github.com/docker-library/php/blob/76a1c5ca161f1ed6aafb2c2d26f83ec17360bc68/7.1/alpine/Dockerfile

I'm using this offical php Docker image: https://github.com/docker-library/php/blob/76a1c5ca161f1ed6aafb2c2d26f83ec17360bc68/7.1/alpine/Dockerfile

现在我需要添加对 yaml 扩展的支持,它没有与 php 捆绑在一起.我看到我使用的基本图像使用了 phpize.

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.

我正在尝试这种方法:

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

但我收到此错误:

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

使用该图像并添加该支持的最惯用的 docker 方式是什么?

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?

推荐答案

Alpine 使用 apk 来安装包.编译过程抱怨缺少 autoconf,它可以在 Alpine 的 autoconf 包中找到.

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 add --no-cache --virtual .build-deps 
    g++ make autoconf yaml-dev

RUN pecl channel-update pecl.php.net
RUN pecl install yaml-2.0.0 && docker-php-ext-enable yaml

RUN apk del --purge .build-deps

如果您需要安装其他非开发库,您可以在单独的 apk add 命令中安装它们.此过程将:

If you need to install other non-dev libraries, you can install them in a separate apk add command. This procedure will:

  1. 安装构建 deps,使用 --no-cache 意味着您使用的是更新的索引而不是本地缓存(因此不需要 --update 或将 pkg 保存在缓存中).--virtual 意味着你正在为所有那些以后可以删除的包创建一个虚拟引用(因为它们在编译过程之后就没有用了)

  1. 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)

用 pecl 和 docker-php-ext-enable 做你的事情

do your stuff with pecl and docker-php-ext-enable

删除之前的构建依赖

如果你仍然遇到任何缺失的依赖,你可以参考这个:https://pkgs.alpinelinux.org/包

If you still encounter any missing dependency, you can see as reference this: https://pkgs.alpinelinux.org/packages

这篇关于使用官方的 Alpine Docker 镜像将 yaml 扩展添加到 php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆