I created my Dockerfile where I want to create a simple Spring Boot Webapp listening on a port.
FROM java:8
VOLUME /tmp
ENV port=123
#WORKDIR /workdir
ADD /target/docker-test-0.1.jar dockertest.jar
EXPOSE $port
RUN bash -c 'touch /dockertest.jar'
#ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom -Dserver.port=$port","-jar","/dockertest.jar"]
ENTRYPOINT java -jar /dockertest.jar -Djava.security.egd=file:/dev/./urandom -Dserver.port=$port
My webapps application.properties defines the following:
server.port=666
Starting my docker container via IntelliJ Docker Plugin I give it the parameter:
port=555
Running docker inspect bootapp
(bootapp is the containers name) gives me following information about the port environment variable and the entrypoint:
"Entrypoint" : [ "/bin/sh", "-c", "java -jar /dockertest.jar -Djava.security.egd=file:/dev/./urandom -Dserver.port=$port" ],
"Env" : [ "port=555", ...],
And Spring Boots log says this:
2017-08-30 20:10:07.709 INFO 5 --- [main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 666 (http)
So the port defined in application.properties
was not overwritten by a runtime parameter.
This tells me that EXPOSE=$port
actually was able to be resolved but the variable in ENTRYPOINT wasn't.
I already changed ENTRYPOINT to shell form but that did not helped as you can see through my Dockerfile
The system variable was at the wrong place in the java execution command. It has to be place before the
-jar
option.Wrong
Right