Created
August 22, 2016 11:01
-
-
Save onnimonni/66366d4cefae9b7634f0dfb9224cdbe6 to your computer and use it in GitHub Desktop.
Docker startup script to setup all ENVs to PHP-FPM ENVs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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