Search code examples
dockerpeclsilent-installer

Silently Installing pecl modules (e.g. pecl_http) Inside a Docker Container?


I am attempting to install pecl_http inside a docker container. Currently my Dockerfile looks something like this:

FROM fun:5000/apache-php:0.1.0

# Install dependencies
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && \
    apt-get -y install \
        php5-dev \
        libcurl4-openssl-dev && \

    yes "\n" | pecl install pecl_http-1.7.6 && \
    echo "extension=http.so" > /etc/php5/mods-available/http.ini && \
    cd /etc/php5/apache2/conf.d/ && \
    ln -s ../../mods-available/http.ini 20-http.ini && \
    ...

Initially I was simply using pecl install pecl_http-1.7.6 in the docker file, and the container built successfully - without pecl_http installed.

If I attach to the container, I can install pecl_http with the interactive pecl install pecl_http-1.7.6 by simply hitting enter after every prompt. I just learned about yes, and it seemed to fit my needs. Online searches indicated that many people have used it to perform unattended pecl installs, including pecl_http; however, when I attempt to use it in my docker container it fails with configure: error: could not find magic.h.

How can I perform a silent pecl_http install in Docker?


Solution

  • Your pecl install is asking you this question:

    whether to enable response content type guessing; specify libmagic directory [no] :

    And yes "\n" isn't doing what you think it is - it's actually outputting:

    \n
    \n
    \n
    \n
    \n
    \n
    

    So because you're saying \n in response to the above question, the installer thinks you're telling it to look in \n for libmagic, and of course it's failing because \n is nonsense.

    yes has an implicit return after each command you tell it to output, so if you want to just have it hit return and use the defaults, use yes ''.

    Working Dockerfile:

    FROM ubuntu:14.04
    
    # Install dependencies
    ENV DEBIAN_FRONTEND noninteractive
    RUN apt-get update
    RUN apt-get -y install php5-dev
    RUN apt-get -y install libcurl4-openssl-dev
    RUN apt-get -y install libevent-dev
    RUN echo "extension=http.so" > /etc/php5/mods-available/http.ini
    RUN yes "" | pecl install pecl_http-1.7.6
    RUN cd /etc/php5/apache2/conf.d/
    RUN ln -s ../../mods-available/http.ini 20-http.ini
    ...
    

    Extra tip: Don't be afraid to split your commands out into separate RUN statements to make full use of the docker cache.