I'm using docker-maven-plugin
and as per the documentation I need to pass environment variable file via <envPropertyFile>
. So the plugin in pom.xml looks like
<configuration>
<images>
<image>
<build>
...
</build>
<run>
<envPropertyFile>${project.basedir}/local/local.properties</envPropertyFile>
</run>
</image>
</images>
</configuration>
I have local.properties with below values,
TIME_COUNT=1000
REST=10
In my java project I read those values as
System.getenv("TIME_COUNT"); #which returns null.
Troubleshooting:
1.When I check env inside the container I see TIME_COUNT=1000 and REST=10
.
docker exec -it CONTAINER_ID bash
env
2.When I execute
docker inspect -f '{{range $index, $value := .Config.Env}}{{println $value}}{{end}}' CONTAINER_ID
I see all env values ( i.e TIME_COUNT=1000, REST=10 )
3.In my java when I tried to retrieve all the env I get none of env values from local.properties or the default which I could see inside the container by doing env
.
StringBuilder sb = new StringBuilder();
Map<String, String> env = System.getenv();
for (String key : env.keySet()) {
sb.append(key + ": " + env.get(key) + "\n");
}
System.out.println(sb.toString());
4.I also tried passing env variable as mentioned below, which overwrote the value in container but the jar file still throwing null.
docker exec -e TIME_COUNT=12 -it CONTAINER_ID bash