spring-bootdockerkotlinenvironment-variablesspring-bean-dsl

Environment variables from Docker are not passed to Spring


I try to dockerize simple java application.

my Dockerfile:

FROM adoptopenjdk/openjdk11:alpine
COPY build/libs/*.jar app.jar
ENTRYPOINT java -Djava.security.egd=file:/dev/./urandom -jar /app.jar
EXPOSE 8080

In my bean definition file I try to log properties:

    beans {
        bean {
            logger.info { "System env: " + env.systemEnvironment }
            // ...
        }
    }

but when I call:

docker run 123 --env foo=bar 

It results in foo not being visible from java.

However if I run my application from Idea and pass environment variables directly it works as a charm.

Am I missing something? How I can make values passed in env available for java?


Solution

  • You should try with

    docker run -env foo=bar your_image:tag
    

    And in code,

    env.getProperty("foo")