使用 PHP zip 扩展构建的 Docker 映像显示“不推荐使用捆绑的 libzip”警告

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/48700453/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:42:57  来源:igfitidea点击:

Docker image build with PHP zip extension shows "bundled libzip is deprecated" warning

phpdockerphp-extensionlibzip

提问by sakhunzai

I have a Dockerfilewith a build command like this:

我有一个Dockerfile像这样的构建命令:

#install some base extensions
RUN apt-get install -y \
        zlib1g-dev \
        zip \
  && docker-php-ext-install zip

I get this warning from build output:

我从构建输出中收到此警告:

WARNING: Use of bundled libzip is deprecated and will be removed.
configure: WARNING: Some features such as encryption and bzip2 are not available.
configure: WARNING: Use system library and --with-libzip is recommended.

警告:不推荐使用捆绑的 libzip,并将被删除。
配置:警告:某些功能如加密和 bzip2 不可用。
配置:警告:建议使用系统库和--with-libzip。

What is the correct way to install the zip extension without these warnings?

在没有这些警告的情况下安装 zip 扩展的正确方法是什么?

My complete Dockerfile looks like:

我完整的 Dockerfile 看起来像:

FROM php:7.2-apache

RUN apt-get clean
RUN apt-get update

#install some basic tools
RUN apt-get install -y \
        git \
        tree \
        vim \
        wget \
        subversion

#install some base extensions
RUN apt-get install -y \
        zlib1g-dev \
        zip \
  && docker-php-ext-install zip

#setup composer
RUN curl -sS https://getcomposer.org/installer | php \
        && mv composer.phar /usr/local/bin/ \
        && ln -s /usr/local/bin/composer.phar /usr/local/bin/composer


WORKDIR /var/www/

回答by Just a student

It looks likePHP no longer bundles libzip. You need to install it. You install zlib1g-dev, but instead install libzip-dev. This installs zlib1g-devas a dependency and allows the configurescript to detect that libzipis installed.

看起来像PHP不再绑定libzip。你需要安装它。您安装zlib1g-dev,而是安装libzip-dev。这将zlib1g-dev作为依赖项安装,并允许configure脚本检测libzip已安装。

For PHP < 7.3, you then need to

对于 PHP < 7.3,则需要

docker-php-ext-configure zip --with-libzip

before performing the installation with

在执行安装之前

docker-php-ext-install zip

as the last warning indicates.

正如最后一个警告所示。

In short: change the relevant part of your Dockerfile to

简而言之:将 Dockerfile 的相关部分更改为

For PHP < 7.3

对于 PHP < 7.3

#install some base extensions
RUN apt-get install -y \
        libzip-dev \
        zip \
  && docker-php-ext-configure zip --with-libzip \
  && docker-php-ext-install zip

For PHP >= 7.3

对于 PHP >= 7.3

#install some base extensions
RUN apt-get install -y \
        libzip-dev \
        zip \
  && docker-php-ext-install zip

I have verified that this builds as expected.

我已经验证这按预期构建。

 

 



 

 

In case you are not using the Docker PHP base image, things may be much easier. For example, for Alpine the following Dockerfile will get you PHP 7 with the zip extension installed.

如果您没有使用 Docker PHP 基础镜像,事情可能会容易得多。例如,对于 Alpine,以下 Dockerfile 将为您提供安装了 zip 扩展的 PHP 7。

FROM alpine:latest

RUN apk update && apk upgrade
RUN apk add php7 php7-zip composer

回答by Bernard Tai

I built a PHP container on Docker using php:7.2-fpm-alpine

我使用 Docker 在 Docker 上构建了一个 PHP 容器 php:7.2-fpm-alpine

FROM php:7.2-fpm-alpine

WORKDIR /var/www

RUN apk add --no-cache zip libzip-dev
RUN docker-php-ext-configure zip --with-libzip
RUN docker-php-ext-install zip
RUN docker-php-ext-install pdo pdo_mysql 

回答by kimy82

In order to build a php/apache container you just have to first install libzip-devlibrary. At least using the docker image php:7.3-apache

为了构建一个 php/apache 容器,你只需要先安装libzip-dev库。至少使用 docker 镜像 php:7.3-apache

FROM php:7.3-apache
MAINTAINER XXX

RUN apt-get update
RUN apt-get install -y libzip-dev
RUN docker-php-ext-install zip

Hope it helps

希望能帮助到你

回答by Juan Castellon

In case you are using 7.4 this worked for me:

如果您使用的是 7.4,这对我有用:

FROM php:7.4-fpm-alpine

RUN apk add --no-cache zip libzip-dev
RUN docker-php-ext-configure zip
RUN docker-php-ext-install zip
RUN docker-php-ext-install pdo pdo_mysql