13

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.

2 Answers 2

11

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

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

Comments

4

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}

4 Comments

No I guess it must be that I'm using HOSTNAME.
Ya so just tried HOST_IP and set this on the host machine first with export HOST_IP=$(/sbin/ip route|awk '/default/ { print $3 }') this works
I guess docker is stripping out HOSTNAME env variable
Docker is automatically setting some variables: docs.docker.com/engine/reference/run/#env-environment-variables However that does not explain why the HOSTNAME is stripped during compose.yml reading.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.