How to enable php extensions inside a Docker container

1

I need to enable curl but I'm using Docker to manage my application.

I wanted to know how I could change information from php.ini via terminal, I tried with gedit but I did not succeed.

Maybe a solution for Dockerfile, but I'm a layman in those kind of settings.

What is the best way to do these settings?

    
asked by anonymous 03.02.2017 / 03:11

2 answers

0

If you use the official PHP image for Docker, you can install the extensions by running the docker-php-ext-install command. If the extension has any prerequisites, it must be installed from its Dockerfile before executing docker-php-ext-install .

See an example from the image documentation:

FROM php:7.0-fpm
RUN apt-get update && apt-get install -y \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libmcrypt-dev \
        libpng12-dev \
    && docker-php-ext-install -j$(nproc) iconv mcrypt \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install -j$(nproc) gd

About the extent of curl , it is already enabled by default in the official image

root@58d96f139768:/# php -m
[PHP Modules]
Core
ctype
curl
date
dom
fileinfo
filter
ftp
hash
iconv

Since the image you are using is not based on the official image, I suggest you search for another image that is based on the official image, so it is easier for you to make these customizations.

You can take inspiration from in this tutorial here to create the containers for your application.

    
29.05.2017 / 03:52
-1

The best way to do a configuration in a container is to regenerate an image with the correct configuration. You can do this by creating a new INI file, which enables its extension, whereas in dockerfile you must install this extension. Depending on the desired extension, you can use native repositories of the distribution corresponding to the image (the most used base image is debian: jessie that uses APT as a package manager). Example: github.com/docker-gallery/wordpress-apache-php7

But considering your scenario where you already have a container running, use docker exec -it [nomeDoContainer|idDoContainer] /bin/bash and you will have access to the terminal inside the container. Use the terminal to setup your container.

  

But remember, these files will die with your container. It's healthier to do this earlier in the dockerfile and re-create your container.

    
23.03.2017 / 04:35