compose: WARNING: The X variable is not set. Defaulting to a blank string.
My environment:
# docker-compose version
docker-compose version 1.8.1, build 878cff1
docker-py version: 1.10.3
CPython version: 2.7.12
OpenSSL version: OpenSSL 1.0.2h 3 May 2016
#
I’m seeing following WARNING message:
# docker-compose ps
WARNING: The ELK variable is not set. Defaulting to a blank string.
Name Command State Ports
---------------------------------------------------------------------------------------
nginx_nginx_1 nginx -g daemon off; Up 0.0.0.0:443->443/tcp, 0.0.0.0:80->80/tcp
#
Per Environment variables in Compose - Docker:
# grep ELK docker-compose.yaml
gelf-address: "udp://${ELK}:12201"
#
# grep -A1 env_file docker-compose.yaml
env_file:
- docker-compose.env
# grep ELK docker-compose.env
ELK=172.17.0.2
#
Please advise.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 52
- Comments: 28
Commits related to this issue
- Rename env_file ".env" to "qualitas.env" and add .env The ".env" file has special meaning in docker compose, it is meant for defining the defaults for variables used in the docker compose files. See ... — committed to openstax/qualitas-server by karenc 5 years ago
- Rename env_file ".env" to "qualitas.env" and add .env (#73) The ".env" file has special meaning in docker compose, it is meant for defining the defaults for variables used in the docker compose file... — committed to openstax/qualitas-server by karenc 5 years ago
- Variables in Docker-Compose In order to use a variable in a docker-compose file, they need to be defined: 1. In the local context (i.e., if you echo $VAR on the local machine, you'll get a result... — committed to stephencweiss/docker-crud by stephencweiss a year ago
You need to escape the variable if you want it to be expanded inside the container, using a double-dollar sign (
$${ELK}
). If however, you want it to be interpreted on your host, the $ELK needs to be defined in your environment or in the.env
file. Theenv_file
option defines environment variables that will be available inside the container only.just for future googlers. my problem was with environment variables not being passed through
sudo
(e.g. on Ubuntu). Working solution:To reiterate what I wrote earlier in this thread:
environment
andenv_file
sections of the Compose file declare variables that will be available inside the container.$VAR
or${VAR}
syntax inside the Compose file are replaced by the value found on the host machine (i.e. the machine you’re executingdocker-compose
from) at the time of execution. They’re found either in the OS’s environment or the statically named.env
file.$$VAR
or$${VAR}
) to escape the sequence.That feels a lot like a bug. There shouldn’t be “too specific” behavior. It only confuses people.
It’s not intuitive to me that the file specified by the “env_file” directive acts differently than the “.env” file…
However @shin- 's comment made it clear to me… the “.env” file’s vars are available at docker-compose stage whereas all other env vars set via env_file or env directive are only available within the container… ok
Found this issue first in the search for a resolution, and ended up understanding then solving it with the info here: http://staxmanade.com/2016/05/how-to-get-environment-variables-passed-through-docker-compose-to-the-containers/
Specifically; set the variable in
./.env
, which makes it available to substitute indocker-compose.yml
then in
docker-compose.yml
, pass it through to the container with:edit: added
./
to make it clear we are not talking about<file>.env
@oojacoboo $UID is not an environment variable, it’s a shell variable:
See #2380
@shin- can you explain what I’m missing here?
I get this:
WARNING: The UID variable is not set. Defaulting to a blank string.
However:
My problem was that I tried to execute
docker compose
from a subdirectory, not a root directory where.env
file exists@a1exus
./docker-compose.env
!=./.env
I managed to find a solution! I used the
env_file
setting itself, and defined the filevariables.env
within the same line. And it worked like a charm!Here is how my docker-compose.yml looks like:
you can also use .env in root of your project it does same…
Hello, I am problem with set variable in yaml file: docker-compose build master WARNING: The CI_ARTEFACTS_HOSTPATH variable is not set. Defaulting to a blank string. Building master … (cut log)
I am use:
docker-compose --version docker-compose version 1.24.0-rc1, build 0f3d4dda
docker-compose.yaml:
This example may help if you would like to provide default value in docker-compose env:
Use
"${ENV_VAR:-defaultValue}"
Using
.env
can override default url.Using double dollar signs fixed it for me:
It is mentioned in the official documentation here:
The X variable is not set. Defaulting to a blank string.
https://docs.docker.com/compose/environment-variables/
For those who can’t/don’t want to use a
./.env
file you can pass in the sameenv_file:
entry as a command line argument and it will work for making the values available at build time:My problem is that I am using white space in .env file You should remove all spaces
->
Per @Joshfindit I’ve tried with
.env
and everything works like a charm! Thank you!