Docker在支持curl的高山图像上构建php失败。我该如何解决?

时间:2019-06-13 13:03:13

标签: php docker curl dockerfile

我尝试在php:7-fpm-alpine映像上为PHP安装curl支持。因此,我使用以下Dockerfile

FROM php:7-fpm-alpine

RUN apk add --update libzip-dev libcurl &&\
    docker-php-ext-install curl && \
    apk del gcc g++ &&\
    rm -rf /var/cache/apk/*

但是与此question类似,尽管使用libcurl安装了所需的库,我还是很难安装所需的apk,如构建输出所示:

Building base
Step 1/2 : FROM php:7-fpm-alpine
 ---> 3a7affb05baa
Step 2/2 : RUN apk add --update libzip-dev libcurl &&    docker-php-ext-install curl &&     apk del gcc g++ &&    rm -rf /var/cache/apk/*
 ---> Running in 27a225ce5f91
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/community/x86_64/APKINDEX.tar.gz
(1/4) Installing pkgconf (1.6.0-r0)
(2/4) Installing zlib-dev (1.2.11-r1)
(3/4) Installing libzip (1.5.1-r2)
(4/4) Installing libzip-dev (1.5.1-r2)
Executing busybox-1.29.3-r10.trigger
OK: 18 MiB in 34 packages
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/community/x86_64/APKINDEX.tar.gz
(1/24) Installing m4 (1.4.18-r1)
(2/24) Installing libbz2 (1.0.6-r6)
(3/24) Installing perl (5.26.3-r0)
(4/24) Installing autoconf (2.69-r2)
(5/24) Installing dpkg-dev (1.19.2-r0)
(6/24) Installing dpkg (1.19.2-r0)
(7/24) Installing libmagic (5.36-r0)
(8/24) Installing file (5.36-r0)
(9/24) Installing libgcc (8.3.0-r0)
(10/24) Installing libstdc++ (8.3.0-r0)
(11/24) Installing binutils (2.31.1-r2)
(12/24) Installing gmp (6.1.2-r1)
(13/24) Installing isl (0.18-r0)
(14/24) Installing libgomp (8.3.0-r0)
(15/24) Installing libatomic (8.3.0-r0)
(16/24) Installing mpfr3 (3.1.5-r1)
(17/24) Installing mpc1 (1.0.3-r1)
(18/24) Installing gcc (8.3.0-r0)
(19/24) Installing musl-dev (1.1.20-r4)
(20/24) Installing libc-dev (0.7.1-r0)
(21/24) Installing g++ (8.3.0-r0)
(22/24) Installing make (4.2.1-r2)
(23/24) Installing re2c (1.1.1-r0)
(24/24) Installing .phpize-deps (0)
Executing busybox-1.29.3-r10.trigger
OK: 218 MiB in 58 packages
Configuring for:
PHP Api Version:         20180731
Zend Module Api No:      20180731
Zend Extension Api No:   320180731
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-musl
checking host system type... x86_64-pc-linux-musl
checking target system type... x86_64-pc-linux-musl
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-20180731
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... 1.1.1 (ok)
checking for gawk... no
checking for nawk... no
checking for awk... awk
checking if awk 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.15.5 or greater... configure: error: cURL version 7.15.5 or later is required to compile php with cURL support
Removing intermediate container 27a225ce5f91
ERROR: Service 'base' failed to build: The command '/bin/sh -c apk add --update libzip-dev libcurl &&    docker-php-ext-install curl &&     apk del gcc g++ &&    rm -rf /var/cache/apk/*' returned a non-zero code: 1

我还尝试将以下内容更改为我的Dockerfile(已使用curl的{​​{1}})

libcurl

也失败了:

FROM php:7-fpm-alpine

RUN apk add --update libzip-dev curl &&\
    docker-php-ext-install curl && \
    apk del gcc g++ &&\
    rm -rf /var/cache/apk/*

您知道如何解决此问题吗?

2 个答案:

答案 0 :(得分:3)

您可能需要curl-dev软件包。

FROM php:7-fpm-alpine

RUN apk add --update libzip-dev curl-dev &&\
    docker-php-ext-install curl && \
    apk del gcc g++ &&\
    rm -rf /var/cache/apk/*

答案 1 :(得分:1)

如果遇到此类问题,您也可以在袖子中使用以下王牌:

  1. 启动一个单独的容器并搜索该软件包:
docker run -ti php:7-fpm-alpine /bin/sh
apk update && apk search libcurl
  1. 然后,如果找不到合适的软件包,则尝试构建缺少的库。

@Qteb说丢失的软件包是curl-dev