Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Composer Install (own Container) with Docker missing PHP Extensions

I am currently learning about Docker, and using it for 2 weeks. Now i have a very simple task, installing PHP Libraries via Composer. That is usually, when working without Docker:

composer install

Now since i am using Docker, i found there is a Docker Container, that is holding composer for me:

docker run --rm -v $(pwd):/app composer/composer install

This is working pretty good, but there is some libraries out there, that require specific php libraries to be installed, like bcmath, so i add this to my Dockerfile

FROM php:7.0-apache
RUN docker-php-ext-install bcmath <-- added this line 
COPY . /var/www/html
WORKDIR /var/www/html
EXPOSE 80

When i rebuild my container, this code returns true

var_dump(extension_loaded('bcmath'))

Hooray! BCMath is installed correctly, but composer does not recognize it, because the library is not installed in the composer container!

Now i could ignore that by using

docker run --rm -v $(pwd):/app composer/composer install --ignore-platform-reqs

but this is, in my opinion, a dirty workound, and composer can not validate my platform. Is there any clean solution, besides downloading composer in my Dockerfile and not reusing an existing container?

like image 911
CBergau Avatar asked Jul 02 '16 15:07

CBergau


1 Answers

You may use platform settings to mimic your PHP container configuration. This will work similar to --ignore-platform-reqs switch (it will use PHP and extensions configured in composer.json instead of real info from current PHP installation), but it gives you more granular control. Instead of "ignore all platform requirements checks" you may say "I really have bcmath installed, trust me". All other requirements will be checked, so you still be warned if new requirement will pop-up.

"config": {
    "platform": {
        "php": "7.1",
        "ext-bcmath": "*"
    }
},
like image 186
rob006 Avatar answered Sep 17 '22 20:09

rob006