I have a Docker container running systemd. I want to pass environment variables to applications under it.
When I start systemd from within Docker (/sbin/init
as command line), Docker exposes variables to systemd, but does not expose to child services. If I add systemd.setenv=...
to the cmdline, the variables are passed. I am looking for a cleaner solution.
How do I expose environment variables passed to /sbin/init
to applications started by it?
% docker run -v /sys/fs/cgroup:/sys/fs/cgroup:ro --privileged -ti \
-e VAR1=1 motiejus/systemd_fedora20 \
init systemd.setenv=VAR2=2
...
Welcome to Fedora 20 (Heisenbug)!
...
[ OK ] Reached target Multi-User System.
[root@740690365eb0 ~]# env | grep VAR
VAR2=2
I expect to see VAR1=1
while running my command.
In other words, can systemd pass variables passed to it to children it starts?
For Dockerfile, see github repository.