4

I'm working with an app using docker (i'm not super familiar) and I need to add 2 new PHP extensions. I have changed the Dockerfile on an existing image as follows:

FROM php:7.2-fpm

RUN apt-get update

RUN apt-get install -y git unzip

RUN php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer

RUN apt-get install -y git libpng-dev \
    && docker-php-ext-install gd

RUN apt-get install -y mysql-client \
    && docker-php-ext-configure pdo_mysql --with-pdo-mysql=mysqlnd \
    && docker-php-ext-install pdo_mysql

RUN apt-get install -y libgmp-dev bcmath \
    && docker-php-ext-configure gmp \
    && docker-php-ext-install gmp \
    && docker-php-ext-install bcmath

RUN pecl install xdebug \
    && docker-php-ext-enable xdebug

ADD docker/templates/usr/local/etc/php/conf.d/uploads.ini /usr/local/etc/php/conf.d/uploads.ini

My new lines are:

RUN apt-get install -y libgmp-dev bcmath \
&& docker-php-ext-configure gmp \
&& docker-php-ext-install gmp \
&& docker-php-ext-install bcmath

I tried docker-compose restart, I tried docker-compose down followed by docker-compose up, I removed the container entirely and re-created with up. However hard I try, I always get this error when doing a composer require

the requested PHP extension bcmath is missing from your system.

I'm not sure why this is happening. Why won't the extension install, and how come if I completely delete the contents and write garbled text in the Dockerfile, it always runs successfully. Is it caching it?

Can somebody explain how I'd re-provision with the new changes I made?

Snippet of docker-compose.yml:

services:
  web:
    build:
      context: ./
      dockerfile: docker/web.docker
    working_dir: /var/www
    volumes:
      - ./:/var/www
    ports:
      - 81:80
  app:
    build:
      context: ./
      dockerfile: docker/app.docker
    working_dir: /var/www
    volumes:
      - ./:/var/www
    environment:
      - "LARAVEL_ENVIRONMENT=local"
montrealist
  • 5,593
  • 12
  • 46
  • 68
simonw16
  • 960
  • 9
  • 25
  • I've also tried `php7.0-bcmath`, `php7.1-bcmath` and `php-bcmath`. None of which work. – simonw16 Mar 22 '19 at 23:03
  • 1
    How do you build a Docker image? This instruction added to docker-compose or you build it with a command? – Dmitrii Mar 22 '19 at 23:16
  • Oh I have to rebuild the image? I didn't know the containers and images are separate, so you have to explicitly rebuild the image and then spin up containers? I guess I suspected it'd be like vagrant where you just vagrant up and it does everything in one – simonw16 Mar 22 '19 at 23:23
  • "If you want to force Compose to stop and recreate all containers, use the --force-recreate flag." I read that from the docs, which made be believe thats what I needed to do. – simonw16 Mar 22 '19 at 23:25

1 Answers1

6

You need to rebuild the image

docker-compose build

and next re-run containers

docker-compose up -d
Dmitrii
  • 877
  • 1
  • 6
  • 12