Use Docker env vars with PHP 5.2.x Use Docker env vars with PHP 5.2.x docker docker

Use Docker env vars with PHP 5.2.x


most probably those env are overridden somewhere in image you are using.docker compose allows to define a command to run on startup. So you can override env vars on startup to whatever you need:

command: bash -c "DB_HOST='mariadb:3306' && DB_USER='some_user ... & ./start_something.sh"

EDIT:

as comment mentioned php require all env to be in php-fpm.conf. strange as for me but it's easy enough to work around by adding env vars you need into this file in same command: statement of docker compose. Simple echo "ENV_NAME" >> ..../php-fpm.conf should help you.

or you can modify Dockerfile so your image has simple sh script which would dump all env vars into that php config.

i am modifying mongo config so works as replica set - works like a charm.


I found an XML file at /usr/local/etc/php-fpm.conf that contained the Environment variables, and filled it in using dockerize

<value name="environment">    <!-- Add docker environment variables -->    {{ range $k,$v := .Env }}{{ $parts := split $k "APP_" }}{{ if eq (len $parts) 2 -}}    <value name="{{ index $parts 1 }}">{{ $v }}</value>    {{ end }}{{- end -}}    <!-- End Docker Env -->

With docker-compose having

environment:    APP_DB_HOST: mariadb:3306    APP_DB_USER: ${DB_USER}    APP_DB_PASSWORD: ${DB_PASSWORD}     APP_DB_DATABASE: ${DB_DATABASE}

enter image description here