I'm building an image that is based on an ubuntu image with systemd. I need to start TigerVNC as a service which depends on some environment variables that I have defined in my Dockerfile, like the password.
FROM ubuntu-systemd
ENV VNC_PW="some-password"
ENTRYPOINT ["/lib/systemd/systemd"]
The unit file for this service has a line that is:
ExecStart=/usr/sbin/runuser -l root -c "/some/script.sh"
Since systemd has its own environment, I don't have access to the environment variables defined in my Dockerfile. I was expecting that running the script as root with a login shell (the '-l' flag) would give me access to these variables but it does not. I know the variables I need are in /proc/1/environ but I don't know how to load them, for example adding something in the .profile file for root.
Thank you.
A little bit tricky but I can load the environment variables in the /some/script.sh in the ExecStart property by including the following line:
export `xargs --null --max-args=1 echo < /proc/1/environ`