def docker_environment ( env ) : return ' ' . join ( [ "-e \"%s=%s\"" % ( key , value . replace ( "$" , "\\$" ) . replace ( "\"" , "\\\"" ) . replace ( "`" , "\\`" ) ) for key , value in env . items ( ) ] )
python docker configuration passing environment varialbes
Transform dictionary of environment variables into Docker - e parameters .
def docker_environment(env):
    """
    Transform dictionary of environment variables into Docker -e parameters.

    >>> result = docker_environment({'param1': 'val1', 'param2': 'val2'})
    >>> result in ['-e "param1=val1" -e "param2=val2"', '-e "param2=val2" -e "param1=val1"']
    True
    """
    return ' '.join(
        ["-e \"%s=%s\"" % (key, value.replace("$", "\\$").replace("\"", "\\\"").replace("`", "\\`"))
         for key, value in env.items()])