【问题标题】:Docker failed to install cURL (version 7.10.5 or later is required)Docker 安装 cURL 失败(需要 7.10.5 或更高版本)
【发布时间】:2019-05-07 17:32:27
【问题描述】:

我在尝试使用 dockercomposer.json 安装 Stripe 时出错。

这是我的composer.json

{
"require": {
    "smarty/smarty": "^3.1",
    "stripe/stripe-php": "^6.13"
    }
}

我的Dockerfile

FROM php:7.2.6-apache
RUN docker-php-ext-install mysqli curl

以及我docker-compose up时的错误日志

Build complete.
Don't forget to run 'make test'.

Installing shared extensions:     /usr/local/lib/php/extensions/no-debug-non-zts-20170718/
Installing header files:          /usr/local/include/php/
find . -name \*.gcno -o -name \*.gcda | xargs rm -f
find . -name \*.lo -o -name \*.o | xargs rm -f
find . -name \*.la -o -name \*.a | xargs rm -f
find . -name \*.so | xargs rm -f
find . -name .libs -a -type d|xargs rm -rf
rm -f libphp.la       modules/* libs/*
Configuring for:
PHP Api Version:         20170718
Zend Module Api No:      20170718
Zend Extension Api No:   320170718
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for PHP prefix... /usr/local
checking for PHP includes... -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib
checking for PHP extension directory... /usr/local/lib/php/extensions/no-debug-non-zts-20170718
checking for PHP installed headers prefix... /usr/local/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... re2c
checking for re2c version... 0.16 (ok)
checking for gawk... no
checking for nawk... nawk
checking if nawk is broken... no
checking for cURL support... yes, shared
checking for pkg-config... /usr/bin/pkg-config
checking for libcurl.pc... using default path
checking for cURL 7.10.5 or greater... configure: error: cURL version 7.10.5 or later is required to compile php with cURL support
ERROR: Service 'www' failed to build: The command '/bin/sh -c docker-php-ext-install mysqli curl' returned a non-zero code: 1

我找不到任何解决方法,或者我做错了什么。感谢您的帮助

【问题讨论】:

    标签: php docker curl docker-compose dockerfile


    【解决方案1】:

    “docker-php-ext-install”帮助脚本旨在安装 PHP 扩展,而不是系统包。在您的 Dockerfile 中,您将需要以下内容:

    FROM php:7.2.6-apache
    RUN apt-get update -y && apt-get install -y curl && apt-get clean -y
    RUN docker-php-ext-install mysqli
    

    mysqli 是一个 PHP 扩展,所以应该没问题。 (我建议使用 PDO,但这是一个不同的对话。)

    【讨论】:

    • 嗨大卫,docker-compose up 时出错:Lock file, outdated dependencies。所以我更新了它:composer update --lock。这是错误:Your requirements could not be resolved to an installable set of packages. Problem 1 - stripe/stripe-php v6.34.5 requires ext-curl * -> the requested PHP extension curl is missing from your system.。我想我必须在php.ini中激活它们,在哪里可以找到这个文件?
    • 啊,好的。您需要使用 PHP 来进行 curl。现在清楚多了。查看这个 GitHub 问题,其中他们有一个类似的问题,看起来已经解决:github.com/docker-library/php/issues/323 看起来两个 apt-get 都需要安装系统 dep。安装 ext-curl 需要 cURL 和 docker-php-ext-install。
    • 在我的 Dockerfile 中添加了它:FROM php:7.2.6-apache RUN apt-get update -y && apt-get install -y curl libcurl3-dev && apt-get clean -y RUN docker-php-ext-install mysqli 同样的错误:composer update --lock PHP 警告:PHP 启动:无法加载动态库 'curl'(试过:/usr/lib/php/20170718 /curl (/usr/lib/php/20170718/curl: 无法打开共享对象文件: 没有这样的文件或目录), /usr/lib/php/20170718/curl.so (/usr/lib/php/20170718/curl .so:无法打开共享对象文件:没有这样的文件或目录))在第 0 行的未知
    • 报错提示apt-get install -y curl没有安装系统包cURL。我会检查一下系统包是为 Debian 发行版命名的。
    【解决方案2】:

    我的一个朋友给出的解决方案。 cURL 已经在 php 包中,无需安装。但情况更复杂。我的Dockerfile

    FROM composer AS vendor
    
    COPY composer.json .
    COPY composer.lock .
    RUN composer install
    
    FROM php:7.3-apache
    
    COPY --from=vendor /app/vendor/ vendor/
    COPY www ./
    
    RUN mkdir templates_c
    RUN mkdir cache
    RUN chown www-data:www-data templates_c cache
    
    VOLUME /var/www/html/templates_c/
    VOLUME /var/www/html/cache/
    
    RUN docker-php-ext-install mysqli
    

    我的docker-compose.yml

    version: "2"
    services:
        www:
            build: .
            ports: 
                - "80:80"
            volumes:
                - ./www/lib:/var/www/html/lib
                - ./www/modules:/var/www/html/modules
                - ./www/theme:/var/www/html/theme
                - ./www/index.php:/var/www/html/index.php
                - ./www/notes.php:/var/www/html/notes.php
                - ./www/tuto_array.php:/var/www/html/tuto_array.php
            links:
                - db
            networks:
                - default
    

    【讨论】:

    • 您还应该将composer.lock 复制到第一个构建阶段,否则安装将始终下载最新的软件包版本。
    猜你喜欢
    • 1970-01-01
    • 2019-04-15
    • 1970-01-01
    • 2017-10-08
    • 2022-01-13
    • 2014-11-21
    • 2017-04-26
    • 2022-01-17
    • 2020-01-20
    相关资源
    最近更新 更多