Inject env variables inside php.ini, automatically, with Docker

Thomas Decaux
1 min readApr 25, 2020

--

This articles explains, from Docker official php-fpm image, how to inject configuration from env variables.

We are using official Docker image: php-fpm:7.4

Example project =>

This is not another Docker image, but some scripts to copy/paste inside your own Docker image.

The idea is to loop env variables, check if env name is starting by PHP_DEFINE_, then prepend it to php.ini.

As the image have Php, I wrote it as a Php script!

So with that, you can write a base Docker image, for dev & prod purpose, then run it differently:

docker run -ti — rm -p 9000:9000 — env PHP_DEFINE_OPCACHE_ENABLE=On — env PHP_DEFINE_DISPLAY_ERRORS=Off my_super_php

--

--

Thomas Decaux
Thomas Decaux

Responses (1)