How to enable php extensions inside a Docker container

Asked

Viewed 997 times

1

I need to enable Curl but I am 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 did not succeed.

Maybe a solution for Dockerfile, but I’m a layman in those kinds of settings.

How best to make these settings?

  • How is your Dockerfile?

  • I’m using a picture of the Hub, and/and Orange

2 answers

0


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

See an example taken 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

On the extent of curl, it already comes enabled by default in the official image

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

As the image you are using is not based on the official image, I suggest you search for another that suits you and is based on the official image, because it is easier for you to do this type of customizations.

You can be inspired in this tutorial here to create your application containers.

-1

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

But given your scenario where you already have a container running, use docker exec -it [nomeDoContainer|idDoContainer] /bin/bash and 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 before in dockerfile and recreate your container.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.