2016-05-30 194 views
15

爲了resolve an issue,我現在嘗試通過如何通過docker-php-ext-install爲php安裝擴展?

docker-php-ext-install 

安裝MySQL PDO作爲README of the php image指出。

然而,我的電話失敗說明:

Libraries have been installed in: 
    /usr/src/php/ext/mysqli/modules 

If you ever happen to want to link against installed libraries 
in a given directory, LIBDIR, you must either use libtool, and 
specify the full pathname of the library, or use the `-LLIBDIR' 
flag during linking and do at least one of the following: 
    - add LIBDIR to the `LD_LIBRARY_PATH' environment variable 
    during execution 
    - add LIBDIR to the `LD_RUN_PATH' environment variable 
    during linking 
    - use the `-Wl,--rpath -Wl,LIBDIR' linker flag 
    - have your system administrator add LIBDIR to `/etc/ld.so.conf' 

See any operating system documentation about shared libraries for 
more information, such as the ld(1) and ld.so(8) manual pages. 
---------------------------------------------------------------------- 

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

Installing shared extensions:  /usr/local/lib/php/extensions/no-debug-non-zts-20131226/ 
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/* 
+ cd /usr/src/php/ext/mysqlnd 
+ phpize 
Cannot find config.m4. 
Make sure that you run '/usr/local/bin/phpize' in the top level source directory of the module 

ERROR: Service 'phlaconapp' failed to build: The command '/bin/sh -c docker-php-ext-install mysqli mysqlnd pdo pdo_mysql zip' returned a non-zero code: 1 

這是我docker-compose.yml

phlaconapp: 
    hostname: phaclonapp 
    dockerfile: Dockerfile 
    build: ./ 
    ports: 
     - "1080:80" 
     - "1043:433" 
    environment: 
     TERM: xterm-color 
     ENVIRONMENT: dev 
    volumes: 
     - ./:/var/www/html/ 
    links: 
     - mysql 
mysql: 
    image: mysql:5.6 
    volumes: 
     - ./docker/mysql.d:/etc/mysql/conf.d 
    ports: ["3306:3306"] 
    environment: 
     MYSQL_ROOT_PASSWORD: 'root' 

這是我Dockerfile

FROM php:5.6-apache 

RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && \ 
    php -r "if (hash_file('SHA384', 'composer-setup.php') === '070854512ef404f16bac87071a6db9fd9721da1684cd4589b1196c3faf71b9a2682e2311b36a5079825e155ac7ce150d') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" && \ 
    php composer-setup.php && \ 
    php -r "unlink('composer-setup.php');" 


RUN apt-get update && \ 
    apt-get install vim git -y 
RUN docker-php-ext-install mysqli mysqlnd pdo pdo_mysql zip 

RUN cd/&& \ 
    git clone --depth=1 git://github.com/phalcon/cphalcon.git && \ 
    cd cphalcon/build && \ 
    ./install 

RUN echo "extension=phalcon.so" > /usr/local/etc/php/conf.d/phalcon.ini 
RUN a2enmod rewrite 

和運行docker-compose build將無法​​完成。

+1

跟進https://github.com/docker-library/php/issues/233創建 – k0pernikus

回答

7

我曾經有過同樣的問題。我啓動了一個容器,並將ext-install命令輸入到此容器中。一旦我找到所有的依賴關係,我將它們寫入dockerfile。

Exmample:

RUN apt-get update && apt-get install -y \ 
libmcrypt-dev \ 
&& docker-php-ext-install -j$(nproc) mcrypt 

還有就是之前你可以泊塢窗的PHP-EXT安裝mcrypt的

我檢查了我的大Dockerfiles並發現了一些可能需要libmcrypt-dev的一個dependencie幫助你

FROM php:5.6-apache 

RUN apt-get update && apt-get install -y \ 
     libfreetype6-dev \ 
     libjpeg62-turbo-dev \ 
     libmcrypt-dev \ 
     libpng12-dev \ 
    libicu-dev \ 
    libxml2-dev \ 
    vim \ 
     wget \ 
     unzip \ 
     git \ 
    && docker-php-ext-install -j$(nproc) iconv intl xml soap mcrypt opcache pdo pdo_mysql mysqli mbstring \ 
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \ 
    && docker-php-ext-install -j$(nproc) gd 

RUN a2enmod rewrite && mkdir /composer-setup && wget https://getcomposer.org/installer -P /composer-setup && php /composer-setup/installer --install-dir=/usr/bin && rm -Rf /composer-setup && curl -LsS https://symfony.com/installer -o /usr/local/bin/symfony && chmod a+x /usr/local/bin/symfony 
# Create symlink for default conf 
RUN ln -s /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-enabled/000-default.conf && mkdir /composer-setup && wget https://getcomposer.org/installer -P /composer-setup && php /composer-setup/installer --install-dir=/usr/bin && rm -Rf /composer-setup && curl -LsS https://symfony.com/installer -o /usr/local/bin/symfony && chmod a+x /usr/local/bin/symfony 
+0

正因爲如此,我試圖運行的泊塢窗,PHP -ext-install命令在容器內而不是構建後的Dockerfile。他們工作得很好0.o – k0pernikus

+0

參數-y在您的配置中與我的不同。 apt-get install -y而不是apt-get install vim git -y – Florian

0

似乎是在phpizehttps://bugs.php.net/bug.php?id=53571)的錯誤。

我增加了以下內容docker-php-ext-configure

/usr/local/bin # diff -u docker-php-ext-configure.bak docker-php-ext-configure 
--- docker-php-ext-configure.bak 
+++ docker-php-ext-configure 
@@ -54,5 +54,6 @@ 

set -x 
cd "$ext" 
+[[ ! -f "config.m4" && -f "config0.m4" ]] && mv config0.m4 config.m4 
phpize 
./configure "[email protected]"