Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 835
DarVar Avatar asked Feb 12 '16 11:02

DarVar


People also ask

Can I use environment variables in Docker compose file?

In Docker Compose, IT admins can use environment variables to generalize configurations for different situations, deployment environments and security contexts without editing the main project file(s) manually. Variables can either be passed as command-line arguments -- suitable for only a few parameters -- or via a .

Can Docker access host environment variables?

You can pass the values of environment variables from the host to your containers without much effort. Simply don't specify a value in the command line, and make sure that the environment variable is named the same as the variable the containerized app expects: $ docker run -e var_name (...)

How do I set an environment variable in Docker?

Use -e or --env value to set environment variables (default []). If you want to use multiple environments from the command line then before every environment variable use the -e flag. Note: Make sure put the container name after the environment variable, not before that.


1 Answers

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}
like image 125
michaelbahr Avatar answered Sep 20 '22 13:09

michaelbahr