Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RavenDB ignoring environment variables in docker-compose

I am trying to setup a cluster of 3 RavenDB instances using docker-compose and I am having problems with the RavenDB server not picking up the values in the RAVEN_ environment variables.

At first, I was running a single instance, using this docker-compose file:

version: '3'

services:
  ravendb:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "8080:8080"
      - "38888:38888"
    volumes:
      - ../data:/opt/RavenDB/Server/RavenData

With a simple Dockerfile that used the latest raven image and simply copied a settings.json file into the container.

FROM ravendb/ravendb

COPY settings.json /opt/RavenDB/Server/settings.json
{
    "License.Eula.Accepted": true,
    "License": {/*License here*/},
    "Setup.Mode": "Unsecured",
    "Security.UnsecuredAccessAllowed": "PublicNetwork",
    "ServerUrl": "http://0.0.0.0:8080",
    "ServerUrl.Tcp": "tcp://0.0.0.0:38888"
}

Now that I am trying to setup 3 instances, I wanted to avoid this way of creating the containers, since I would have to have different Dockerfiles and a settings.json file for each one. Therefore, I thought of using a single docker-compose file that creates three containers and configures each one with enviroment variables. I started with a single instance, to see if any problems would arise:

version: '3'

services:
  raven1:
    container_name: raven1
    image: ravendb/ravendb
    ports:
      - "8080:8080"
      - "38888:38888"
    environment:
      - RAVEN_Security_UnsecuredAccessAllowed=PublicNetwork
      - RAVEN_Setup_Mode=Unsecured
      - RAVEN_License_Eula_Accepted=true
      - "RAVEN_ServerUrl=http://0.0.0.0:8080"
      - "RAVEN_ServerUrl_Tcp=tcp://0.0.0.0:38888"
    volumes:
      - ../data:/opt/RavenDB/Server/RavenData

And arise they did! Despite the environment variables being set correctly, they are not picked up by the server, and the settings.json file is the default one.

root@8ad95cc439d4:/opt/RavenDB/Server# env
RAVEN_ARGS=
RAVEN_Security_UnsecuredAccessAllowed=PublicNetwork
RAVEN_AUTO_INSTALL_CA=true
RAVEN_ServerUrl=http://0.0.0.0:8080
RAVEN_SETTINGS=
RAVEN_ServerUrl_Tcp=tcp://0.0.0.0:38888
RAVEN_IN_DOCKER=true
RAVEN_Setup_Mode=Unsecured
RAVEN_License_Eula_Accepted=true
RAVEN_DataDir=RavenData
root@8ad95cc439d4:/opt/RavenDB/Server# cat settings.json
{
    "Security.UnsecuredAccessAllowed": "PrivateNetwork"
}

Any idea why this might be happening? I can't seem to find any mention of issues regarding this.

like image 831
António Bezerra Avatar asked Nov 04 '25 10:11

António Bezerra


1 Answers

Do I understand correctly you expected the configuration from environment variables to be included in the settings.json file in the container?

If that's the case I would like to clarify that passing environment variables does not modify RavenDB's settings.json file. Instead RavenDB loads them up directly from the environment.

Configuration options are loaded in the following order of precedence:

  • command line arguments
  • settings.json configuration file
  • RAVEN_ prefixed environment variables

So if you wanted to override the configuration option Security.UnsecuredAccessAllowed found in settings.json file you would need to either change the file on the container or pass it as a CLI argument --Security.UnsecuredAccessAllowed PublicNetwork.

Both cases are supported by RavenDB docker images:

  • to clear the default settings.json you can pass RAVEN_SETTINGS={} environment variable to the container.

  • to pass command line arguments to the RavenDB server binary you can use RAVEN_ARGS environment variable. E.g. RAVEN_ARGS=--Security.UnsecuredAccessAllowed PublicNetwork

like image 72
gregolsky Avatar answered Nov 07 '25 10:11

gregolsky