Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment vars with default values are not available inside compose #4478

Closed
Umkus opened this issue Feb 13, 2017 · 3 comments
Closed

Environment vars with default values are not available inside compose #4478

Umkus opened this issue Feb 13, 2017 · 3 comments

Comments

@Umkus
Copy link

Umkus commented Feb 13, 2017

The issue

Environment variables availability inside compose file provided from the following:

  • shell or .env file
  • defined in compose file

feels inconsistent. Environment vars with default values are not available inside compose unless explicitly provided from outside of it.

The example

Consider the following minimal compose file:

version: '3'
services:
    example:
        environment:
            TAG: edge
        image: alpine:${TAG}

The ${TAG} variable is not available anywhere inside compose file.

E.g.:

$ docker-compose up
WARNING: The TAG variable is not set. Defaulting to a blank string.
Pulling example (alpine:latest)...
...

But:

$ TAG=edge docker-compose up
Pulling example (alpine:edge)...
...

the $TAG is now available inside the compose file.

The outcome

It's required to always explicitly provide env variable values to be able to use them inside compose file.

It feels natural to expect that all env variables are available/resolving inside the compose file, especially those that were defined by it in the first place. Although this seems to not be the case.

Sorry if this was answered before, I didn't find this particular use-case in issues list.

Tech specs:

$ docker version
Client:
 Version:      1.13.1
 API version:  1.26
 Go version:   go1.7.5
 Git commit:   092cba3
 Built:        Wed Feb  8 08:47:51 2017
 OS/Arch:      darwin/amd64

Server:
 Version:      1.13.1
 API version:  1.26 (minimum version 1.12)
 Go version:   go1.7.5
 Git commit:   092cba3
 Built:        Wed Feb  8 08:47:51 2017
 OS/Arch:      linux/amd64
 Experimental: true
$ docker-compose version
docker-compose version 1.11.1, build 7c5d5e4
docker-py version: 2.0.2
CPython version: 2.7.12
OpenSSL version: OpenSSL 1.0.2j  26 Sep 2016
@shin-
Copy link

shin- commented Feb 13, 2017

Please refer to the disambiguation page: https://docs.docker.com/compose/environment-variables/

In short, the environment entry in your compose file declares the environment variables that will be available inside your container/service at runtime. Variable substitution on the other hand is done using the variables present on the host where docker-compose is being executed. Those are two different sets and should remain separate.

@Umkus
Copy link
Author

Umkus commented Feb 14, 2017

Thanks for the clarification!

@Umkus Umkus closed this as completed Feb 14, 2017
@marczahn
Copy link

marczahn commented Mar 28, 2018

I ran into the same problem now but I can't fix it. I have a shell script which is wrapping the docker-compose call:

...
docker-compose $DOCKER_COMPOSE_FILES up $@
...

DOCKER_COMPOSE_FILES is a string with "-f file1.yml -f file2.yml ...". It is all working fine.

My docker-compose image entry is that:

...
image: "...-service:${DOCKER_TAG}"
...

I tried several ways:

  • sourcing the file with the DOCKER_TAG inside the shell script
  • exporting DOCKER_TAG manually in the shell script
  • Call docker-compose with DOCKER_TAG in front:
    DOCKER_TAG=... docker-compose...

Nothing works - DOCKER_TAG is not available. Does someone know what I am doing wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants