我正在尝试使用Docker搭建我的开发环境。这是我第一次使用docker。对于我的项目,我需要在容器中安装php-dbase
扩展。我有一个Dockerfile
,但无法成功安装该扩展。
该扩展可以通过pecl
获取:dbase
我的第一次尝试是这样的:
FROM php:7.4-fpm-alpine
# Install extensions
RUN docker-php-ext-install pdo_mysql
RUN apk add gcc autoconf
RUN pecl install dbase
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
输出:
db@DESKTOP-QOUVTJS:~/.local/git/docker-wsl$ docker-compose -p livemonitor up -d
Building livemonitor
Step 1/5 : FROM php:7.4-fpm-alpine
---> b80da81889cb
Step 2/5 : RUN docker-php-ext-install pdo_mysql
---> Using cache
---> c3bcf3f76995
Step 3/5 : RUN apk add gcc autoconf
---> Running in 867ab7a40f47
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/community/x86_64/APKINDEX.tar.gz
(1/15) Installing m4 (1.4.18-r1)
(2/15) Installing libbz2 (1.0.8-r1)
(3/15) Installing perl (5.30.3-r0)
(4/15) Installing autoconf (2.69-r2)
(5/15) Installing libgcc (9.3.0-r2)
(6/15) Installing libstdc++ (9.3.0-r2)
(7/15) Installing binutils (2.34-r1)
(8/15) Installing gmp (6.2.0-r0)
(9/15) Installing isl (0.18-r0)
(10/15) Installing libgomp (9.3.0-r2)
(11/15) Installing libatomic (9.3.0-r2)
(12/15) Installing libgphobos (9.3.0-r2)
(13/15) Installing mpfr4 (4.0.2-r4)
(14/15) Installing mpc1 (1.1.0-r1)
(15/15) Installing gcc (9.3.0-r2)
Executing busybox-1.31.1-r16.trigger
OK: 175 MiB in 46 packages
Removing intermediate container 867ab7a40f47
---> bd34b111b186
Step 4/5 : RUN pecl install dbase
---> Running in 3772d74eb9ec
downloading dbase-7.0.1.tgz ...
Starting to download dbase-7.0.1.tgz (33,588 bytes)
.........done: 33,588 bytes
15 source files, building
running: phpize
Configuring for:
PHP Api Version: 20190902
Zend Module Api No: 20190902
Zend Extension Api No: 320190902
building in /tmp/pear/temp/pear-build-defaultusercPjDjO/dbase-7.0.1
running: /tmp/pear/temp/dbase/configure --with-php-config=/usr/local/bin/php-config
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 pkg-config... no
checking for cc... cc
checking whether the C compiler works... no
configure: error: in `/tmp/pear/temp/pear-build-defaultusercPjDjO/dbase-7.0.1':
configure: error: C compiler cannot create executables
See `config.log' for more details
ERROR: `/tmp/pear/temp/dbase/configure --with-php-config=/usr/local/bin/php-config' failed
ERROR: Service 'livemonitor' failed to build : The command '/bin/sh -c pecl install dbase' returned a non-zero code: 1
然后我找到了这个脚本:
db@DESKTOP-QOUVTJS:~/.local/git/docker-wsl$ cat .docker/livemonitor/docker-php-ext-get
#!/usr/bin/env sh
set -e
dir=/usr/src/php
if [ ! -f "$dir/.docker-extracted" ]; then
echo >&2 "error: PHP source required, run 'docker-php-source extract' first"
exit 1
fi
dir="$dir/ext"
usage() {
echo "usage: $0 module-name module-version"
echo " ie: $0 redis 4.3.0"
}
name=$1
version=$2
if [ -z "$name" ]; then
usage >&2
exit 1
fi
if [ -z "$version" ]; then
usage >&2
exit 1
fi
mkdir -p "$dir/$name"
curl -fsSL "https://pecl.php.net/get/$name-$version.tgz" | tar xvz -C "$dir/$name" --strip 1
所以我将我的Dockerfile
修改成了这样:
FROM php:7.4-fpm-alpine
COPY docker-php-ext-get /usr/local/bin/
# Install extensions
RUN docker-php-ext-install pdo_mysql
RUN docker-php-source extract &&\
docker-php-ext-get dbase 7.0.1 &&\
docker-php-ext-install dbase pdo_mysql
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
输出:
db@DESKTOP-QOUVTJS:~/.local/git/docker-wsl$ docker-compose -p livemonitor up -d
Building livemonitor
Step 1/5 : FROM php:7.4-fpm-alpine
---> b80da81889cb
Step 2/5 : COPY docker-php-ext-get /usr/local/bin/
---> Using cache
---> 5d56966b8b06
Step 3/5 : RUN docker-php-ext-install pdo_mysql
---> Using cache
---> 3a262b35ac69
Step 4/5 : RUN docker-php-source extract && docker-php-ext-get dbase 7.0.1 && docker-php-ext-install dbase pdo_mysql
---> Running in d854cf08829b
dbase-7.0.1/tests/001.phpt
dbase-7.0.1/tests/002.phpt
dbase-7.0.1/tests/bug31754.phpt
dbase-7.0.1/tests/bug39305.phpt
dbase-7.0.1/tests/bug52112.phpt
dbase-7.0.1/tests/bug73391.phpt
dbase-7.0.1/tests/bug73395.phpt
dbase-7.0.1/tests/bug73411.phpt
dbase-7.0.1/tests/bug73414.dbf
dbase-7.0.1/tests/bug73414.phpt
dbase-7.0.1/tests/bug73442.phpt
dbase-7.0.1/tests/bug73447.phpt
dbase-7.0.1/tests/bug78070.phpt
dbase-7.0.1/tests/bug78668.phpt
dbase-7.0.1/tests/bug78668.dbf
dbase-7.0.1/tests/dbase_add_record_basic.phpt
dbase-7.0.1/tests/dbase_add_record_error.phpt
dbase-7.0.1/tests/dbase_add_record_variation1.phpt
dbase-7.0.1/tests/dbase_add_record_variation2.phpt
dbase-7.0.1/tests/dbase_add_record_variation3.phpt
dbase-7.0.1/tests/dbase_add_record_variation4.phpt
dbase-7.0.1/tests/dbase_close_error.phpt
dbase-7.0.1/tests/dbase_create_basic.phpt
dbase-7.0.1/tests/dbase_create_error.phpt
dbase-7.0.1/tests/dbase_create_error_open_basedir.phpt
dbase-7.0.1/tests/dbase_create_variation1.phpt
dbase-7.0.1/tests/dbase_create_variation2.phpt
dbase-7.0.1/tests/dbase_create_variation3.phpt
dbase-7.0.1/tests/dbase_delete_record_basic.phpt
dbase-7.0.1/tests/dbase_delete_record_error_32bit.phpt
dbase-7.0.1/tests/dbase_delete_record_error_64bit.phpt
dbase-7.0.1/tests/dbase_delete_record_variation1.phpt
dbase-7.0.1/tests/dbase_get_header_info_basic.phpt
dbase-7.0.1/tests/dbase_get_header_info_error.phpt
dbase-7.0.1/tests/dbase_get_record_basic.phpt
dbase-7.0.1/tests/dbase_get_record_error_32bit.phpt
dbase-7.0.1/tests/dbase_get_record_error_64bit.phpt
dbase-7.0.1/tests/dbase_get_record_with_names_basic.phpt
dbase-7.0.1/tests/dbase_get_record_with_names_error_32bit.phpt
dbase-7.0.1/tests/dbase_get_record_with_names_error_64bit.phpt
dbase-7.0.1/tests/dbase_get_record_with_names_variation1.phpt
dbase-7.0.1/tests/dbase_numfields_basic.phpt
dbase-7.0.1/tests/dbase_numfields_error.phpt
dbase-7.0.1/tests/dbase_numrecords_basic.phpt
dbase-7.0.1/tests/dbase_numrecords_error.phpt
dbase-7.0.1/tests/dbase_open_error.phpt
dbase-7.0.1/tests/dbase_open_error1.dbf
dbase-7.0.1/tests/dbase_open_error1.phpt
dbase-7.0.1/tests/dbase_open_error2.dbf
dbase-7.0.1/tests/dbase_open_error2.phpt
dbase-7.0.1/tests/dbase_open_error3.dbf
dbase-7.0.1/tests/dbase_open_error3.phpt
dbase-7.0.1/tests/dbase_open_error_open_basedir.phpt
dbase-7.0.1/tests/dbase_pack_basic.phpt
dbase-7.0.1/tests/dbase_pack_error.phpt
dbase-7.0.1/tests/dbase_pack_variation1.phpt
dbase-7.0.1/tests/dbase_pack_variation2.phpt
dbase-7.0.1/tests/dbase_replace_record_basic.phpt
dbase-7.0.1/tests/dbase_replace_record_error.phpt
dbase-7.0.1/tests/dbase_replace_record_error_1_32bit.phpt
dbase-7.0.1/tests/dbase_replace_record_error_1_64bit.phpt
dbase-7.0.1/tests/dbase_replace_record_variation1.phpt
dbase-7.0.1/tests/dbase_replace_record_variation2.phpt
dbase-7.0.1/tests/dbase_replace_record_variation3.phpt
dbase-7.0.1/tests/example.dbf
dbase-7.0.1/tests/nullable.phpt
dbase-7.0.1/tests/type_datetime.phpt
dbase-7.0.1/tests/type_logical.phpt
dbase-7.0.1/tests/type_numeric_int_32bit.phpt
dbase-7.0.1/tests/type_numeric_int_64bit.phpt
dbase-7.0.1/config.m4
dbase-7.0.1/config.w32
dbase-7.0.1/CREDITS
dbase-7.0.1/dbase.c
dbase-7.0.1/dbf.h
dbase-7.0.1/dbf_head.c
dbase-7.0.1/dbf_head.h
dbase-7.0.1/dbf_misc.c
dbase-7.0.1/dbf_misc.h
dbase-7.0.1/dbf_ndx.c
dbase-7.0.1/dbf_ndx.h
dbase-7.0.1/dbf_rec.c
dbase-7.0.1/dbf_rec.h
dbase-7.0.1/dbf_sdncal.h
dbase-7.0.1/gregor.c
dbase-7.0.1/LICENSE
dbase-7.0.1/php_dbase.h
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/community/x86_64/APKINDEX.tar.gz
(1/26) Installing m4 (1.4.18-r1)
(2/26) Installing libbz2 (1.0.8-r1)
(3/26) Installing perl (5.30.3-r0)
(4/26) Installing autoconf (2.69-r2)
(5/26) Installing pkgconf (1.7.2-r0)
(6/26) Installing dpkg-dev (1.20.0-r0)
(7/26) Installing dpkg (1.20.0-r0)
(8/26) Installing libmagic (5.38-r0)
(9/26) Installing file (5.38-r0)
(10/26) Installing libgcc (9.3.0-r2)
(11/26) Installing libstdc++ (9.3.0-r2)
(12/26) Installing binutils (2.34-r1)
(13/26) Installing gmp (6.2.0-r0)
(14/26) Installing isl (0.18-r0)
(15/26) Installing libgomp (9.3.0-r2)
(16/26) Installing libatomic (9.3.0-r2)
(17/26) Installing libgphobos (9.3.0-r2)
(18/26) Installing mpfr4 (4.0.2-r4)
(19/26) Installing mpc1 (1.1.0-r1)
(20/26) Installing gcc (9.3.0-r2)
(21/26) Installing musl-dev (1.1.24-r9)
(22/26) Installing libc-dev (0.7.2-r3)
(23/26) Installing g++ (9.3.0-r2)
(24/26) Installing make (4.3-r0)
(25/26) Installing re2c (1.3-r1)
(26/26) Installing .phpize-deps (20201004.101402)
Executing busybox-1.31.1-r16.trigger
OK: 255 MiB in 57 packages
Configuring for:
PHP Api Version: 20190902
Zend Module Api No: 20190902
Zend Extension Api No: 320190902
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 pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
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 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-20190902
checking for PHP installed headers prefix... /usr/local/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for gawk... no
checking for nawk... no
checking for awk... awk
checking if awk is broken... no
checking whether to enable dbase support... yes, shared
checking for a sed that does not truncate output... /bin/sed
checking for ld used by cc... /usr/x86_64-alpine-linux-musl/bin/ld
checking if the linker (/usr/x86_64-alpine-linux-musl/bin/ld) is GNU ld... yes
checking for /usr/x86_64-alpine-linux-musl/bin/ld option to reload object files... -r
checking for BSD-compatible nm... /usr/bin/nm -B
checking whether ln -s works... yes
checking how to recognize dependent libraries... pass_all
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking dlfcn.h usability... yes
checking dlfcn.h presence... yes
checking for dlfcn.h... yes
checking the maximum length of command line arguments... 98304
checking command to parse /usr/bin/nm -B output from cc object... ok
checking for objdir... .libs
checking for ar... ar
checking for ranlib... ranlib
checking for strip... strip
checking if cc supports -fno-rtti -fno-exceptions... no
checking for cc option to produce PIC... -fPIC
checking if cc PIC flag -fPIC works... yes
checking if cc static flag -static works... yes
checking if cc supports -c -o file.o... yes
checking whether the cc linker (/usr/x86_64-alpine-linux-musl/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
creating libtool
appending configuration tag "CXX" to libtool
configure: patching config.h.in
configure: creating ./config.status
config.status: creating config.h
/bin/sh /usr/src/php/ext/dbase/libtool --mode=compile cc -I. -I/usr/src/php/ext/dbase -DPHP_ATOM_INC -I/usr/src/php/ext/dbase/include -I/usr/src/php/ext/dbase/main -I/usr/src/php/ext/dbase -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 -fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DHAVE_CONFIG_H -fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -c /usr/src/php/ext/dbase/dbf_head.c -o dbf_head.lo
mkdir .libs
cc -I. -I/usr/src/php/ext/dbase -DPHP_ATOM_INC -I/usr/src/php/ext/dbase/include -I/usr/src/php/ext/dbase/main -I/usr/src/php/ext/dbase -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 -fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DHAVE_CONFIG_H -fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -c /usr/src/php/ext/dbase/dbf_head.c -fPIC -DPIC -o .libs/dbf_head.o
/usr/src/php/ext/dbase/dbf_head.c: In function 'dbf_open':
/usr/src/php/ext/dbase/dbf_head.c:346:41: error: 'LOCK_EX' undeclared (first use in this function)
346 | if (php_flock(fd, (o_flags == O_RDWR ? LOCK_EX : LOCK_SH))) {
| ^~~~~~~
/usr/src/php/ext/dbase/dbf_head.c:346:41: note: each undeclared identifier is reported only once for each function it appears in
/usr/src/php/ext/dbase/dbf_head.c:346:51: error: 'LOCK_SH' undeclared (first use in this function)
346 | if (php_flock(fd, (o_flags == O_RDWR ? LOCK_EX : LOCK_SH))) {
| ^~~~~~~
/usr/src/php/ext/dbase/dbf_head.c:352:17: error: 'LOCK_UN' undeclared (first use in this function)
352 | php_flock(fd, LOCK_UN);
| ^~~~~~~
make: *** [Makefile:191: dbf_head.lo] Error 1
ERROR: Service 'livemonitor' failed to build : The command '/bin/sh -c docker-php-source extract && docker-php-ext-get dbase 7.0.1 && docker-php-ext-install dbase pdo_mysql' returned a non-zero code: 2
我不知道该从哪里开始。如果能得到任何帮助,我将不胜感激。
提前感谢。