[systemd-devel] Pass environment variables down to systemd-service in container

Peter Paule systemd-devel at fedux.org
Tue Jun 16 08:49:27 PDT 2015


Excerpts from Lennart Poettering's message of 2015-06-15 00:32:09 +0200:
> 
> Nope, we deliberately clean up the env block we pass to services.
> 

Mmmh, would it possible to add some kind of a whitelist for environment
variables to the systemd- and/or service.unit-configuration for
variables which are passed on to services? Maybe something like
http://httpd.apache.org/docs/2.2/mod/mod_env.html#passenv.

This would make things a lot of easier when containers are used with
systemd as process supervisor. At least for Ruby on Rails or other
software which makes use of environment variables for configuration.

This way I can build a single image I can use in different environments
just by setting environment files. Does that make sense to you?

Outer Service Units
  # Service 1
  ExecStart="docker run -e RAILS_ENV=production -e DATABASE_URL="postgresql://localhost/app_production centos-rails"
  
  # Service 2
  ExecStart="docker run -e RAILS_ENV=staging -e DATABASE_URL="postgresql://localhost/app_staging centos-rails"

Inner Service Units (Example)
  PassEnv="RAILS_ENV"
  ExecStart="RAILS_ENV=${RAILS_ENV} /srv/app/bin/rails"


> You can reimport the env vars though by reading them from
> /proc/1/environ. Needs some manual hackery though... 

Just for the records: Or bind mount an environment file, though I don't
like it. It looks like a hack, too.

  ExecStart="docker run -v /opt/app/rails_env:/etc/default/app/environment.conf"

/pp


More information about the systemd-devel mailing list