Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.