Lets consider these commands:
We starting docker image with php 7.2 based on alpine.
docker run -it php:7.2-fpm-alpine3.7 sh
We trying to install php-mongodb as any other extension
docker-php-ext-install mongodb
But we obtaining error:
error: /usr/src/php/ext/mongodb does not exist
usage: /usr/local/bin/docker-php-ext-install [-jN] ext-name [ext-name
...]
ie: /usr/local/bin/docker-php-ext-install gd mysqli
/usr/local/bin/docker-php-ext-install pdo pdo_mysql
/usr/local/bin/docker-php-ext-install -j5 gd mbstring mysqli pdo pdo_mysql shmop
if custom ./configure arguments are necessary, see docker-php-ext-configure
Possible values for ext-name:
bcmath bz2 calendar ctype curl dba dom enchant exif fileinfo filter ftp gd gettext gmp hash iconv imap interbase intl json ldap mbstring mysqli oci8 odbc opcache pcntl pdo pdo_dblib pdo_firebird pdo_mysql pdo_oci pdo_odbc pdo_pgsql pdo_sqlite pgsql phar posix pspell readline recode reflection session shmop simplexml snmp soap sockets sodium spl standard sysvmsg sysvsem sysvshm tidy tokenizer wddx xml xmlreader xmlrpc xmlwriter xsl zend_test zip
Some of the above modules are already compiled into PHP; please check
the output of "php -i" to see which modules are already loaded.
I found some images of php with installed mongodb drivers:
https://github.com/Vinelab/docker-php-mongo
https://gist.github.com/ebuildy/ba6820cbe1befaa229d2
https://hub.docker.com/r/spittet/php-mongodb/
All with the same command:
pecl install mongodb
Have docker-php-ext-install
any advantages over pecl
? I saw that most extensions is installed by docker-php-ext-install
. I found this question without answer in issue:
https://github.com/docker-library/php/issues/374
If pecl contains all extensions, but docker-php-ext-install
allow to install constrained list, why it was created?
The answer may become irrelevant to the question. Still, I am adding the following snippet in case someone comes here as I did and can install mongodb extension for php in a docker container. I am using php7.3-fpm. https://www.php.net/manual/en/mongodb.installation.pecl.php
RUN pecl install mongodb \
&& echo "extension=mongodb.so" > $PHP_INI_DIR/conf.d/mongo.ini
You can find explanations in docker-php-ext-install vs pecl issue in the official php
image repository
I am using this command lines and working for me. Get docker container id with docker ps
command and docker exec -it <container id> bash
apt-get update
apt-get install openssl libssl-dev libcurl4-openssl-dev
pecl install mongo
echo "extension=mongo.so" > /usr/local/etc/php/conf.d/mongo.ini
My docker kept complaining that it could not find the mongo.so extension. Finally i figured it out to run the following
RUN apt-get install -y openssl libssl-dev libcurl4-openssl-dev
RUN pecl install mongodb-1.6.0
RUN docker-php-ext-enable /usr/local/lib/php/extensions/no-debug-non-zts-20180731/mongodb.so
It seems like docker wants that you enable a php extension via docker-php-ext-enable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With