Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

install packages from docker-compose.yml into docker container

I am a beginner with docker and docker-compose and i need your help.

I'm making PHP-NGINX-PostgresSQL symfony developement environment using docker-compose.

Here it is :

web:
    image: nginx:1.13.5
    ports:
        - "80:80"
    volumes:
        - ./html:/html
        - ./site.conf:/etc/nginx/conf.d/default.conf
    links:
        - php
php:
    image: php:7-fpm
    volumes:
        - ./html:/html
    links:
       - postgres
postgres:
    image: postgres:9.6.5
    ports:
        - "5432:5432"
    environment:
        POSTGRES_PASSWORD: postgres

Now, i would like to install php7.2-intl into my php container. So i would like to execute something like :

$ sudo LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
$ sudo apt-get update
$ sudo apt-get install php7.2-intl

Could you help me? I'm really stuck and also I dont have a Dockerfile file, just a docker-compose.yml file.

like image 993
TheMackou Avatar asked Dec 19 '22 04:12

TheMackou


1 Answers

To get a PHP docker container with the intl extension, you need to extend the official PHP image.

To do so, declare the use of your own Dockerfile for your PHP image in docker-compose.yml:

services:
  php:
    # Remove this line
    # image: php:7-fpm

    # Add this one instead
    build: './docker/php'
    # ...

Then, add the following Dockerfile file to the docker/php folder:

FROM php:7.1-fpm

RUN apt-get update && apt-get install -y \
        libicu-dev \
    && docker-php-ext-install \
        intl \
    && docker-php-ext-enable \
        intl

You can now run docker-compose build to get your PHP container built with the Intl extension.

A few notes:

  • I prefer to explicitly tell which PHP version I use (here "7.1.x") rather than the more generic "7.x" you defined with php:7-fpm.
  • I preferred to use the docker-php-ext-install and docker-php-ext-enable command utilities provided by the PHP official image (see "How to install more PHP extensions" section in the PHP image documentation).
like image 130
Michaël Perrin Avatar answered Feb 01 '23 23:02

Michaël Perrin