0

I'm developping an application using spring-boot and Docker. For security reasons I want to not use any more application.properties and use only environnement variable.

If you have best practices I will be grateful.

This is a snipet of my docker-compose.yml

version: "2.1"
services:
app_users:
    image: images/app_users
    container_name: app_user_ctn
    build:
      context: ../..
      dockerfile: docker/dev/Dockerfile
    ports:
      - "30333:8080"
    external_links:
      - mysql
    environment:
      SPRING_DATASOURCE_URL: jdbc:mysql://mysql/myDB?autoReconnect=true
      SPRING_DATASOURCE_USERNAME: mysqluser1
      SPRING_DATASOURCE_PASSWORD: mysqlpwsword
      SPRING_DATASOURCE_DRIVER_CLASS_NAME: com.mysql.jdbc.Driver
      LDAP_PASSWORD: ldapPswd
      LDAP_URLS: ldap://myServer:389
      LDAP_USERNAME: cn=admin,dc=com,dc=expl

When I make a request to ldap I get NulPointerException because ldap environnement variables are not initialize.
When I use application.yml it works.

...
spring:
  ldap:
      password: ldapPswd
      urls: ldap://myServer:389
      username: cn=admin,dc=com,dc=expl
 ....

Would you have any ideas ?

Best regards

4
  • 1
    LDAP_PASSWORD != spring.ldap.password. You should use SPRING_LDAP_PASSWORD.
    – M. Deinum
    Commented Jun 15, 2017 at 8:52
  • you could use 1 env variable for spring boot defining your application properties as json and all should work out of the box
    – pandaadb
    Commented Jun 15, 2017 at 10:09
  • @pandaadb thanks but I don't understand what do you mean
    – Victor
    Commented Jun 15, 2017 at 12:19
  • 1
    @Victor you can read it here: docs.spring.io/spring-boot/docs/current/reference/html/… The SPRING_APPLICATION_JSON properties can be supplied on the command line with an environment variable. For example in a UN*X shell: $ SPRING_APPLICATION_JSON='{"foo":{"bar":"spam"}}' java -jar myapp.jar. The way i read that is that you can define all properties in json format using the above variable and that way you don't have to specify X variables in your docker file. It is just a personal preference thing
    – pandaadb
    Commented Jun 15, 2017 at 12:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.