Skip to content

Instantly share code, notes, and snippets.

@yozik04
Created November 24, 2016 14:32
Show Gist options
  • Save yozik04/400b6bff8a98d1678a80fde6c8e102e9 to your computer and use it in GitHub Desktop.
Save yozik04/400b6bff8a98d1678a80fde6c8e102e9 to your computer and use it in GitHub Desktop.
PHP 7 fpm, alpine, mongodb and composer
FROM php:7-fpm-alpine
RUN apk --update add --virtual build-dependencies build-base openssl-dev autoconf \
&& pecl install mongodb \
&& docker-php-ext-enable mongodb \
&& apk del build-dependencies build-base openssl-dev autoconf \
&& rm -rf /var/cache/apk/*
# Time Zone
RUN echo "date.timezone=${PHP_TIMEZONE:-UTC}" > $PHP_INI_DIR/conf.d/date_timezone.ini
# Register the COMPOSER_HOME environment variable
ENV COMPOSER_HOME /composer
# Add global binary directory to PATH and make sure to re-export it
ENV PATH /composer/vendor/bin:$PATH
# Allow Composer to be run as root
ENV COMPOSER_ALLOW_SUPERUSER 1
# Setup the Composer installer
RUN curl -o /tmp/composer-setup.php https://getcomposer.org/installer \
&& curl -o /tmp/composer-setup.sig https://composer.github.io/installer.sig \
&& php -r "if (hash('SHA384', file_get_contents('/tmp/composer-setup.php')) !== trim(file_get_contents('/tmp/composer-setup.sig'))) { unlink('/tmp/composer-setup.php'); echo 'Invalid installer' . PHP_EOL; exit(1); }" \
&& php /tmp/composer-setup.php --install-dir=/usr/bin --filename=composer
# use composer this way: RUN composer require "mongodb/mongodb=^1.0.0"
@MehGokalp
Copy link

Thank you for sharing

@muratcakmaksoftware
Copy link

or try this

RUN apk update \
    && apk add --no-cache \
    ${PHPIZE_DEPS} \
    && pecl install mongodb \
    && docker-php-ext-enable \
    mongodb \
    && apk del \
    ${PHPIZE_DEPS}

@clpir3s
Copy link

clpir3s commented Apr 17, 2023

Many thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment