Setting a container env. variable dynamically at start

Hi

I’m trying to figure out how to be able to configure an app inside a container on container start or second best at compose build…

The thing is that we have several environment silos. Each silo has a particullar dns suffix, like beta.dbb.dk, live.dbb.dk etc.
We clone machines between silos, mostly from live to BETA/ALPHA/NGT etc. so we want those machines to work out of the box in all silos.

So I have a docker host machine running several internal systems in each their container. Some of these containers need to have a setting set to an url so the service can be hit from outside. Graylog is one of them having a setting: - GRAYLOG_HTTP_EXTERNAL_URI=http://graylog.ngt.dbb.dk:80/

So I would like to be able to set this env. variable dynamically on container startup, by running a command or maybe having the variable set in the compose file. Allthough then we need to rebuild after the machine has been clonned from one silo to another.

The command to get the suffix is like this: $(grep search /etc/resolv.conf | cut -f2 -d" " | tr ‘[:upper:]’ ‘[:lower:]’)

So optimally it would be something like this in the compose file:

environment:
  ...
command: export GRAYLOG_HTTP_EXTERNAL_URI ='graylog.'$$(grep search /etc/resolv.conf | cut -f2 -d" " | tr '[:upper:]' '[:lower:]')'/80'
depends_on:
  ....

This does not work, and I have tried so many configuration of the command but had no success what so ever to set the env. variable inside the container.

Do anyone here have a good suggestion how to solve this challenge?

Any suggestions appriciated.

Best regards, Peter