Skip to content

Instantly share code, notes, and snippets.

@onnimonni
Created August 22, 2016 11:01
Show Gist options
  • Save onnimonni/66366d4cefae9b7634f0dfb9224cdbe6 to your computer and use it in GitHub Desktop.
Save onnimonni/66366d4cefae9b7634f0dfb9224cdbe6 to your computer and use it in GitHub Desktop.
Docker startup script to setup all ENVs to PHP-FPM ENVs
#!/bin/bash
##
# This startup script adds all docker container ENVs to php-fpm ENVs by adding them into static config file
##
php_config_file=/etc/php-fpm.d/env.conf
# Don't recreate the php-fpm file if it exists ( the container was restarted )
if [ ! -f $php_config_file ];
then
# Init comments into file
echo "; This file contains all ENV from docker" >> $php_config_file
echo "" >> $php_config_file
# Loop all docker envs without system envs
for env in $(env -u PATH -u PWD -u SHLVL -u TERM -u HOME -u HOSTNAME -u no_proxy -u _ -u EDITOR -u MANPATH); do
# Extract key and value from 'KEY=VALUE' format
env_key=$(echo $env | cut -f1 -d '=')
env_value=$(echo $env | cut -f2 -d '=')
# Skip empty ENVs
if [ "$env_value" == "" ]; then
continue
fi
# Add all docker envs to php-fpm
echo "env[\"${env_key}\"] = \"${env_key}\"" >> $php_config_file
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment