spring-bootdockerdocker-volumekubernetes-secretsdocker-secrets

How can I natively load docker secrets mounted as a volume in spring boot


How can my spring boot application running inside a container access docker secrets mounted as a volume inside that same container?

Commonly suggested methods I DO NOT want to use:


Solution

  • Spring boot 2.4 introduced this feature as part of Volume mounted config trees using the spring.config.import property.
    To read docker secrets mounted as a volume from the default location set:

    spring.config.import = configtree:/run/secrets/
    

    The property name will be derived from the secret filename and the value from the file contents. This can then be accessed like any other spring property.