1

I'm trying to modify environment variables of my application via docker-compose.yml file.

My appsettings.Development.json looks like below:

{
  "ConnectionStrings": {
    "DefaultConnection": "Server=127.0.0.1,1433;Database=app;User Id=sa;Password=P@ssw0rd"
  },
  "EventBusSettings": {
    "HostAddress": "amqp://guest:guest@localhost:5672"
  },
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "Roles": [
    "Member",
    "Admin"
  ]
}

Using docker-compose.yml I modify ConnectionStrings:DefaultConnection and EventBusSettings:HostAddress like in example below:

# ...
app:
    image: app
    container_name: app
    build:
      context: .
      dockerfile: Services/App/Dockerfile
    ports:
      - 5000:5000
    depends_on:
      - db
      - rabbitmq
      - portainer
    environment:
      - ConnectionStrings:DefaultConnection=Server=db,1433;Database=app;User Id=sa;Password=P@ssw0rd
      - EventBusSettings:HostAddress=amqp://guest:guest@rabbitmq:5672
# ...

How can I modify first element of Roles in appsettings.Development.json via docker-compose.yml?

1
  • 1
    Not sure if you can assign a list there, you could try to access first index using Roles[0]=somevalue. If this is not possible you could still create a new Dockerfile / Image from your existing one and add your json config at the right place, replacing the existing one you want to overwrite. If you need more flexibility you could use templating in that conf file and replace while building container Commented Jun 20, 2021 at 18:21

1 Answer 1

3

You do it by setting Roles__0 to the value you want.

Sign up to request clarification or add additional context in comments.

1 Comment

Can you please extend the exmaple to more details, many thanks

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.