FROM centos:6
RUN useradd appuser
CMD env|grep JAVA_OPTIONS|awk -F= '{print "export "$1"=\""$2"\""}'>/etc/profile.d/00_java-env.sh;bash
docker build -t javaenv .
docker run -it -e JAVA_OPTIONS="-DjvmProperty1=1 -DjvmProperty2=2" javaenv
Observe:
printenv
on root includesJAVA_OPTIONS
(as it would by default)su - appuser
wipes the environment variables set fromdocker run ... -e
(assu -
is intended to), but since we wrote theJAVA_OPTIONS
to/etc/profile.d/
it is shared globally between all users (at least on CentOS) andprintenv
for appuser still includes the JAVA_OPTIONS passed to docker initially :)