Reputation: 8667
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
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:
If pecl contains all extensions, but docker-php-ext-install
allow to install constrained list, why it was created?
Upvotes: 11
Views: 43575
Reputation: 307
For Laravel there is a package https://github.com/jenssegers/laravel-mongodb
So in dockerfile there is a line:
pecl install mongodb && docker-php-ext-enable mongodb
I used these commands to successfully install mongodb on my laravel app ( which is PHP :) )
Upvotes: 0
Reputation: 131
To install smoothly on behalf php:8.2-fpm Docker image try this:
RUN pecl install mongodb && docker-php-ext-enable mongodb
Upvotes: 1
Reputation: 3714
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
Upvotes: 11
Reputation: 386
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
Upvotes: 3
Reputation: 370
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
Upvotes: 3
Reputation: 1780
You can find explanations in docker-php-ext-install vs pecl issue in the official php
image repository
Upvotes: 3