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

Env files parsing #12174

Closed
present-g opened this issue Sep 30, 2024 · 3 comments · Fixed by #12179
Closed

Env files parsing #12174

present-g opened this issue Sep 30, 2024 · 3 comments · Fixed by #12179
Assignees
Labels
area/env .env and env_file kind/feature

Comments

@present-g
Copy link

We still have a problem with different parsing of env files in docker compose and docker run

Files:

.env.test

TEST_VAR='{"key": "value"}'

test.Dockerfile

FROM ubuntu

CMD echo "$TEST_VAR"

test.docker-compose.yaml

services:
  service:
    build:
      dockerfile: test.Dockerfile
    env_file: .env.test
    image: test-image

Execution:

docker compose -f test.docker-compose.yaml up --build => {"key": "value"}
docker run --env-file .env.test test-image => '{"key": "value"}'

We need unified results, otherwise, apps may not work correctly

Docker version 27.1.1, build 6312585
Docker Compose version v2.29.1-desktop.1

Originally posted by @present-g in #2854 (comment)

@ndeloof ndeloof changed the title Env fieles parsing Env files parsing Oct 1, 2024
@ndeloof
Copy link
Contributor

ndeloof commented Oct 1, 2024

Docker Compose .env file parser is not strictly equivalent to the one used by docker run, because the former manages variable interpolation while the latter just consider values as raw string, including quotes.

There's no workaround for this. A possible fix would be to give you an option to explicitly request env file to be loaded without compose to manage values:

services:
  service:
    env_file: 
      path: .env.test
      format: raw # default is to parse with interpolation

@present-g
Copy link
Author

Docker Compose .env file parser is not strictly equivalent to the one used by docker run, because the former manages variable interpolation while the latter just consider values as raw string, including quotes.

And that's the issue. Docker's primary goal is to ensure that everything runs consistently across all environments.

format: raw - is it working now? I've never seen that before

@ndeloof
Copy link
Contributor

ndeloof commented Oct 1, 2024

introducing format is my proposal to offer a fix for this issue, it has to be implemented

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/env .env and env_file kind/feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants