Vectorface / dunit

Test code against multiple versions of PHP with the help of docker
MIT License
248 stars 12 forks source link

How to add PHP extensions to docker images? #11

Closed bishopb closed 9 years ago

bishopb commented 9 years ago

I've noticed that the Dockerfile for 5.4 (and probably others) accepts a build parameter of $PHP_EXTRA_BUILD_DEPS.

How can I tweak and pass this variable into the Dockerfile when pulling the images through dUnit?

For example, something along the lines of: PHP_EXTRA_BUILD_DEPS='pdo pdo_mysql' ./vendor/bin/dunit -i -p

danbruce commented 9 years ago

You'll need to create your own docker image to use. I'd recommend using the PHP 5.4 as a template.

  1. Create a folder called custom-image (or whatever you want to call it).
  2. Copy the Dockerfile that I linked above into this folder.
  3. Edit the Dockerfile. On line 2 change FROM vectorface/php-base to FROM vectorface/php5.4. On line 3 add additional debian packages you want (php5-mysql, etc).
  4. Run docker build -t custom-image (replace the folder name). When it's done you'll have your own image called custom-image.
  5. Edit your .dunitconfig to use your own image instead of the defaults. Or you can use ./vendor/bin/dunit -i custom-image.
bishopb commented 9 years ago

Thanks, that did it nicely! The resulting Dockerfile:

# builds a Debian wheezy image with PHP 5.4
FROM vectorface/php5.4
ENV DUNIT_INSTALL_PACKAGES php5-cli php-apc php5-curl php5-gd php5-intl php5-json php5-mcrypt
ENV LOCAL_INSTALL_PACKAGES php5-imap php5-ldap php5-mysql
RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
RUN \
    apt-get -y update && \
    apt-get -y install $DUNIT_INSTALL_PACKAGES $LOCAL_INSTALL_PACKAGES && \
    apt-get -y autoremove && \
    apt-get -y clean && \
    rm -rf /var/lib/apt/lists/*
bishopb commented 9 years ago

Dockerfile for PHP 5.5 on Debian Wheezy with additional modules:

# Creates a Debian wheezy image with PHP 5.5
# docker build -t my-image path/to/my-image/
FROM vectorface/php5.5
ENV DUNIT_INSTALL_PACKAGES php5-cli php5-apcu php5-curl php5-gd php5-intl php5-json php5-mcrypt
ENV LOCAL_INSTALL_PACKAGES php5-imap php5-ldap php5-mysql
RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
RUN \
    apt-get update && \
    apt-get -y update && \
    apt-get install -y curl
RUN \
    echo 'deb http://packages.dotdeb.org wheezy all'           >> /etc/apt/sources.list && \
    echo 'deb-src http://packages.dotdeb.org wheezy all'       >> /etc/apt/sources.list && \
    echo 'deb http://packages.dotdeb.org wheezy-php55 all'     >> /etc/apt/sources.list && \
    echo 'deb-src http://packages.dotdeb.org wheezy-php55 all' >> /etc/apt/sources.list && \
    curl -O http://www.dotdeb.org/dotdeb.gpg && \
    apt-key add dotdeb.gpg
RUN \
    apt-get -y update && \
    apt-get -y install $DUNIT_INSTALL_PACKAGES $LOCAL_INSTALL_PACKAGES && \
    apt-get -y autoremove && \
    apt-get -y clean && \
    rm -rf /var/lib/apt/lists/*

To do the same for 5.6, search & replace: