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

Inconsistent environment variable resolution #8360

Closed
Kolyunya opened this issue Jun 1, 2021 · 2 comments
Closed

Inconsistent environment variable resolution #8360

Kolyunya opened this issue Jun 1, 2021 · 2 comments

Comments

@Kolyunya
Copy link

Kolyunya commented Jun 1, 2021

Description of the issue

Context information (for bug reports)

Output of docker-compose version

docker-compose version 1.29.2, build unknown
docker-py version: 4.4.4
CPython version: 3.9.2
OpenSSL version: OpenSSL 1.1.1k  25 Mar 2021

Output of docker version

Client:
 Version:           20.10.5
 API version:       1.41
 Go version:        go1.16
 Git commit:        55c4c88966
 Built:             Wed Mar  3 16:51:54 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server:
 Engine:
  Version:          20.10.5
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16
  Git commit:       363e9a88a1
  Built:            Wed Mar  3 16:51:28 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.4.4
  GitCommit:        05f951a3781f4f2c1911b05e61c160e9c30eaa8e.m
 runc:
  Version:          1.0.0-rc93
  GitCommit:        12644e614e25b05da6fd08a38ffa0cfe1903fdec
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Steps to reproduce the issue

  1. Create .env file file with the following contents:
COMPOSE_PROJECT_NAME=default
APPLICATION_NAME=${COMPOSE_PROJECT_NAME}
  1. Create docker-compose.yml file with the following contents:
version: "3.3"
services:
    project-name:
        container_name: ${COMPOSE_PROJECT_NAME}-nginx
        image: nginx:latest
    application-name:
        container_name: ${APPLICATION_NAME}-nginx
        image: nginx:latest
  1. Run COMPOSE_PROJECT_NAME=custom docker-compose config

Observed result

services:
  application-name:
    container_name: default-nginx
    image: nginx:latest
  project-name:
    container_name: custom-nginx
    image: nginx:latest
version: '3.3'

Expected result

services:
  application-name:
    container_name: custom-nginx
    image: nginx:latest
  project-name:
    container_name: custom-nginx
    image: nginx:latest
version: '3.3'

Additional information

Here we see that ${COMPOSE_PROJECT_NAME} inside the docker-compose.yml file is taken from the environment and overrides the value provided in the .env file.

The problem is that ${COMPOSE_PROJECT_NAME} inside the .env file is not taken from the environment which is inconsistent.

This looks like a bug to me. I think that variable resolution should work identically inside .env and docker-compose.yaml files.

At a very least it should be documented somewhere. I couldn't find any documentation on how variables are resolved inside the .env file.

@Kolyunya Kolyunya changed the title Questionable environment variable resolution process Inconsistent environment variable resolution process Jun 1, 2021
@Kolyunya Kolyunya changed the title Inconsistent environment variable resolution process Inconsistent environment variable resolution Jun 1, 2021
@stale
Copy link

stale bot commented Apr 16, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Apr 16, 2022
@stale
Copy link

stale bot commented Apr 27, 2022

This issue has been automatically closed because it had not recent activity during the stale period.

@stale stale bot closed this as completed Apr 27, 2022
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

1 participant