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:
printenvon root includesJAVA_OPTIONS(as it would by default)su - appuserwipes the environment variables set fromdocker run ... -e(assu -is intended to), but since we wrote theJAVA_OPTIONSto/etc/profile.d/it is shared globally between all users (at least on CentOS) andprintenvfor appuser still includes the JAVA_OPTIONS passed to docker initially :)