DarVar
DarVar

Reputation: 18114

Docker-compose using host environment variable

I'm trying to do the following in my docker-compose.yml

But I hit this warning? WARNING: The HOSTNAME variable is not set. Defaulting to a blank string

environment: KAFKA_ADVERTISED_HOST_NAME: ${HOSTNAME}

The HOSTNAME environment variable is obviously set on the host.

Upvotes: 13

Views: 7807

Answers (2)

elyas-bhy
elyas-bhy

Reputation: 792

You just need to export your environment variable to the docker-compose process. Try this instead:

$ export HOSTNAME
$ docker-compose up

Source: https://forums.docker.com/t/docker-compose-not-seeing-environment-variables-on-the-host/11837/2

Upvotes: 11

michaelbahr
michaelbahr

Reputation: 4953

An error saying the variable is not set looks strange indeed.

I use host variables like this:

mycontainer:
  image: <repo>/<image>:${SERVICE_VERSION}
  environment:
    - DB_USER=${DB_USER}
    - DB_PASS=${DB_PASS}

Upvotes: 4

Related Questions