When you run
bash -c 'FOO=bar', a new
bash instance is spawned which executes the
FOO=bar command and then immediately terminates. The
FOO variable exists for a tiny fraction of a second and is then gone, like it never existed.
The example documentation you're referring to does something else, which is very similar to this:
bash -c 'export FOO=bar; run_some_entry_point'
The details are a little different; a script is executed using
source to define the variables and
&& is used to join the commands to avoid running the entry point if the
source command fails:
bash -c 'source file_containing_variable_exports && run_some_entry_point'
The most important point is that this is a single command executed by a single shell instance. The shell instance defines the variables which are marked for export, and then in that environment where those exported variables exist, it launches the container (or whatever) entry point.
This version of the above command will not work:
bash -c 'export FOO=bar'; run_some_entry_point
Here, the bash instance which defined the environment variable terminates, taking the variable away with it; the original shell runs the entry point, without that variable.
By the way, to run a command with some environment variables, you don't need to use a separate
export command. The shell has a syntax for that:
bash -c 'FOO=bar some_program arg ...'
Multiple variables can be given. These variables are not set into the shell's own environment; they are just added to the executed program.