Java will read static property files literally and doesn't do any interpolation of these files before running. There are a few options available to you.
One is to add to the Dockerfile a step to search and replace the value in the file.
FROM java:alpine
ARG SERVICE=test
ENV SERVICE $SERVICE
COPY runtime.properties /tmp/
RUN sed -i -e 's/${SERVICE}/asd/g' /tmp/runtime.properties
RUN chmod 700 /tmp/runtime.properties
Another option is to change the properties file to a java class and read the environment variable directly. This gives the advantage of having the default value in the code for standalone running.
public enum LocalConfig {
INSTANCE;
private String service = System.getenv("SERVICE") ==null ? "test" : System.getenv("SERVICE");
}
Yet another option if you have lots of environment variables is to use envsubst, this will replace all of the environment variables in the file. But this depends on what your base image is. https://www.gnu.org/software/gettext/manual/html_node/envsubst-Invocation.html
FROM java
ARG SERVICE=test
ENV SERVICE $SERVICE
COPY runtime.properties /tmp/
RUN envsubst < /tmp/runtime.properties > /tmp/runtime.properties
RUN chmod 700 /tmp/runtime.properties
The last option I can think of is interpreting the environment variables after you inport the file. There is a good thread on that here: Regarding application.properties file and environment variable