1

Is there a syntax to reference an environment variable from the host in a Docker env-file.

Specifically I'd like to do something like DOCKER_HOST=${HOSTNAME} where HOSTNAME would come the environment of the machine hosting the docker image.

The above doesn't get any attempt at replacement whatsoever and gets passed into the Docker image literally as ${HOSTNAME}.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
JvmSd121
  • 351
  • 3
  • 17

1 Answers1

0

This is generally not done at the image level, but at runtime, on docker run:

See "How to get the hostname of the docker host from inside a docker container on that host without env vars"

docker run .. -e HOST_HOSTNAME=$(hostname) ..

That does use an environment variable.
You can do so without environment variables, using -h

docker run -h=$(hostname)

But that does not work when your docker run is part of a docker compose. See issue 3840.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250