2017-12-27 506 views
1

我有一個圖像php5.6 + apache,自3周前開始使用,當我構建它時,通過Dockerfile。我使用base image來啓動我的圖像。 一切都很好,直到今天,當我不得不改變php.ini中的一些變量。Dockerfile - 運行apt-get install -y php5-MODULES不再工作 - 「沒有安裝應用程序」。如何解決它?

現在,當我嘗試建立圖像再次我收到此錯誤:

Step 5/173 : RUN apt-get install -y php5-common 
---> Running in 8114082e9931 
Reading package lists... 
Building dependency tree... 
Reading state information... 
Package php5-common is not available, but is referred to by another package. 
This may mean that the package is missing, has been obsoleted, or 
is only available from another source 

E: Package 'php5-common' has no installation candidate 
The command '/bin/sh -c apt-get install -y php5-common' returned a non-zero code: 100 

它似乎正在發生的事情對每個PHP模塊,我嘗試安裝。

這裏是Dockerfile的一部分:

FROM php:5-apache 

## Update apt-get 
RUN apt-get update 

RUN php -m  
RUN php -v 


RUN apt-get install -y php5-common 
RUN apt-get install -y php-calendar 
RUN docker-php-ext-install bcmath 
RUN apt-get install -y php5-mhash 
RUN apt-get install -y php5-intl 
RUN cp /etc/php5/mods-available/intl.ini /usr/local/etc/php/conf.d && ln -s /usr/lib/php5/20131226/intl.so /usr/local/lib/php/extensions/no-debug-non-zts-20131226/intl.so 
RUN apt-get install -y php5-mcrypt 
RUN cp /etc/php5/mods-available/mcrypt.ini /usr/local/etc/php/conf.d && ln -s /usr/lib/php5/20131226/mcrypt.so /usr/local/lib/php/extensions/no-debug-non-zts-20131226/mcrypt.so 
RUN apt-get install -y php5-redis 
RUN cp /etc/php5/mods-available/redis.ini /usr/local/etc/php/conf.d && ln -s /usr/lib/php5/20131226/redis.so /usr/local/lib/php/extensions/no-debug-non-zts-20131226/redis.so 
RUN apt-get install -y php5-mysql 
RUN cp /etc/php5/mods-available/mysql.ini /usr/local/etc/php/conf.d && ln -s /usr/lib/php5/20131226/mysql.so /usr/local/lib/php/extensions/no-debug-non-zts-20131226/mysql.so 
RUN cp /etc/php5/mods-available/opcache.ini /usr/local/etc/php/conf.d 
RUN apt-get install -y php5-gd 
RUN cp /etc/php5/mods-available/gd.ini /usr/local/etc/php/conf.d && ln -s /usr/lib/php5/20131226/gd.so /usr/local/lib/php/extensions/no-debug-non-zts-20131226/gd.so 
RUN apt-get install -y php5-gdcm 
RUN cp /etc/php5/mods-available/gdcm.ini /usr/local/etc/php/conf.d && ln -s /usr/lib/php5/20131226/gdcm.so /usr/local/lib/php/extensions/no-debug-non-zts-20131226/gdcm.so 
RUN apt-get install -y php5-vtkgdcm 
RUN cp /etc/php5/mods-available/vtkgdcm.ini /usr/local/etc/php/conf.d && ln -s /usr/lib/php5/20131226/vtkgdcm.so /usr/local/lib/php/extensions/no-debug-non-zts-20131226/vtkgdcm.so 
RUN apt-get install -y php5-ldap 
RUN cp /etc/php5/mods-available/ldap.ini /usr/local/etc/php/conf.d && ln -s /usr/lib/php5/20131226/ldap.so /usr/local/lib/php/extensions/no-debug-non-zts-20131226/ldap.so 
RUN apt-get install -y php5-xsl 
RUN cp /etc/php5/mods-available/xsl.ini /usr/local/etc/php/conf.d && ln -s /usr/lib/php5/20131226/xsl.so /usr/local/lib/php/extensions/no-debug-non-zts-20131226/xsl.so 
RUN apt-get install -y php5-tidy 
RUN cp /etc/php5/mods-available/tidy.ini /usr/local/etc/php/conf.d && ln -s /usr/lib/php5/20131226/tidy.so /usr/local/lib/php/extensions/no-debug-non-zts-20131226/tidy.so 
RUN apt-get install -y php5-xmlrpc 
RUN cp /etc/php5/mods-available/xmlrpc.ini /usr/local/etc/php/conf.d && ln -s /usr/lib/php5/20131226/xmlrpc.so /usr/local/lib/php/extensions/no-debug-non-zts-20131226/xmlrpc.so 
RUN apt-get install -y php5-pgsql 
RUN cp /etc/php5/mods-available/pgsql.ini /usr/local/etc/php/conf.d && ln -s /usr/lib/php5/20131226/pgsql.so /usr/local/lib/php/extensions/no-debug-non-zts-20131226/pgsql.so 
RUN cp /etc/php5/mods-available/mysqli.ini /usr/local/etc/php/conf.d && ln -s /usr/lib/php5/20131226/mysqli.so /usr/local/lib/php/extensions/no-debug-non-zts-20131226/mysqli.so 
RUN cp /etc/php5/mods-available/pdo.ini /usr/local/etc/php/conf.d && ln -s /usr/lib/php5/20131226/pdo.so /usr/local/lib/php/extensions/no-debug-non-zts-20131226/pdo.so 
RUN cp /etc/php5/mods-available/pdo_mysql.ini /usr/local/etc/php/conf.d && ln -s /usr/lib/php5/20131226/pdo_mysql.so /usr/local/lib/php/extensions/no-debug-non-zts-20131226/pdo_mysql.so 
RUN cp /etc/php5/mods-available/pdo_pgsql.ini /usr/local/etc/php/conf.d && ln -s /usr/lib/php5/20131226/pdo_pgsql.so /usr/local/lib/php/extensions/no-debug-non-zts-20131226/pdo_pgsql.so 
RUN cp /etc/php5/mods-available/readline.ini /usr/local/etc/php/conf.d && ln -s /usr/lib/php5/20131226/readline.so /usr/local/lib/php/extensions/no-debug-non-zts-20131226/readline.so 

#COPYING__php.ini 
RUN cp /etc/php5/cli/php.ini /usr/local/etc/php/ 
RUN ls -l /usr/local/etc/ 


## Setting up php.ini varaibles 
RUN grep '^post_max_size' /usr/local/etc/php/php.ini 
RUN sed -i 's,^post_max_size =.*$,post_max_size = 2048M,' /usr/local/etc/php/php.ini 
RUN grep '^post_max_size' /usr/local/etc/php/php.ini 

RUN grep '^upload_max_filesize' /usr/local/etc/php/php.ini 
RUN sed -i 's,^upload_max_filesize =.*$,upload_max_filesize = 2048M,' /usr/local/etc/php/php.ini 
RUN grep '^upload_max_filesize' /usr/local/etc/php/php.ini 

... 

基本上has no installation candidate錯誤這是工作3個星期前所有模塊。

我怎麼能解決這個問題?

UPDATE

遵循問題看到這個POST

+0

首先,將您的RUN進行分組,因爲當您嘗試安裝時忘記「apt-get update」 – user2915097

回答

1

PHP官方容器圖像自帶助手使它更容易些。這些示例直接來自the PHP repository on Docker

安裝核心擴展mcyrpt你將以下內容添加到您的Dockerfile

RUN docker-php-ext-install -j$(nproc) mcrypt 

一些擴展需要在系統上存在的庫(因爲當你建立你的容器中的擴展已經編譯)。請注意,在這個例子中,所有的命令串在一起,你可能作爲一個個人發出RUN

RUN apt-get update && apt-get install -y libfreetype6-dev \ 
     libjpeg62-turbo-dev \ 
     libmcrypt-dev \ 
     libpng-dev 
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \ 
    && docker-php-ext-install -j$(nproc) gd 

對於PECL擴展,像redismemcached你讓pecl install處理安裝,然後使用docker-php-ext-enable添加相應的.ini文件(S)。與上面的gd示例不同,某些PECL擴展有它們自己的依賴關係,所以您在安裝之前使用apt-get install -y ...添加這些擴展。

RUN pecl install redis-3.1.0 && docker-php-ext-enable redis 

報料它一起,它可能看起來像這樣添加gdredismcrypt

FROM php:5-apache 

RUN apt-get update && apt-get install -y libfreetype6-dev \ 
     libjpeg62-turbo-dev \ 
     libmcrypt-dev \ 
     libpng-dev 
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \ 
    && docker-php-ext-install -j$(nproc) gd 
RUN docker-php-ext-install -j$(nproc) mcrypt 
RUN pecl install redis-3.1.0 && docker-php-ext-enable redis 

RUN php -m 
0

如果你看一下Dockerfile您提供的link到,它有這些行:中-1Pin-Priority

# prevent Debian's PHP packages from being installed 
# https://github.com/docker-library/php/pull/542 
RUN set -eux; \ 
    { \ 
     echo 'Package: php*'; \ 
     echo 'Pin: release *'; \ 
     echo 'Pin-Priority: -1'; \ 
    } > /etc/apt/preferences.d/no-debian-php 

偏愛PHP軟件包時,告訴系統不安裝這些軟件包。 而拉請求正在解釋爲什麼https://github.com/docker-library/php/pull/542

要解決您的問題,您必須使用內置的docker-php-ext-install命令來安裝PHP程序包。這裏是他們的官方頁面的例子https://hub.docker.com/_/php/

FROM php:5-apache 

RUN apt-get update && apt-get install -y \ 
     libfreetype6-dev \ 
     libjpeg62-turbo-dev \ 
     libmcrypt-dev \ 
     libpng-dev \ 
    && docker-php-ext-install -j$(nproc) iconv mcrypt \ 
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \ 
    && docker-php-ext-install -j$(nproc) gd 

祝你好運。

相關問題