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.prod.local not picked up on docker compose up #628

Open
fleonardelli opened this issue May 7, 2024 · 4 comments
Open

.env.prod.local not picked up on docker compose up #628

fleonardelli opened this issue May 7, 2024 · 4 comments
Labels

Comments

@fleonardelli
Copy link

In the docs https://github.com/dunglas/symfony-docker/blob/main/docs/production.md there last section says that you can pass env variables adding the .env.prod.local env_file to compose.prod.yaml.

I've added it, and created .env.prod.local:

SERVER_NAME=your-domain-name.example.com
APP_SECRET=ChangeMe
CADDY_MERCURE_JWT_SECRET=ChangeThisMercureHubJWTSecretKey

So now instead of running:

SERVER_NAME=your-domain-name.example.com \
APP_SECRET=ChangeMe \
CADDY_MERCURE_JWT_SECRET=ChangeThisMercureHubJWTSecretKey \
docker compose -f compose.yaml -f compose.prod.yaml up -d --wait

I want to run
docker compose -f compose.yaml -f compose.prod.yaml up -d --wait

But I keep getting:
WARN[0000] The "CADDY_MERCURE_JWT_SECRET" variable is not set. Defaulting to a blank string.
WARN[0000] The "CADDY_MERCURE_JWT_SECRET" variable is not set. Defaulting to a blank string.

If I run it
CADDY_MERCURE_JWT_SECRET=ChangeThisMercureHubJWTSecretKey docker compose -f compose.yaml -f compose.prod.yaml up -d --wait

The container stops restarting, but if I run
export
within the container, I can see the SERVER_NAME is the one from the .env variable and not from the .env.prod.local

I can't figure out how to make it pick up .env.prod.local.

@7-zete-7
Copy link

7-zete-7 commented May 8, 2024

Hello @fleonardelli!

You can say to Docker Compose to use non-default .env-file by setting --env-file option or by using the env_file attribute in (one of) compose.yaml file (see https://docs.docker.com/compose/environment-variables/set-environment-variables/).

@maxhelias maxhelias added support Support requested cannot reproduce labels May 14, 2024
@maxhelias
Copy link
Collaborator

Can you provide a reproducer pls ?

@fleonardelli
Copy link
Author

Run: git clone https://github.com/dunglas/symfony-docker.git .

Modify the compose.prod.yaml to:

# Production environment override
services:
  php:
    env_file:
      - .env.prod.local
    build:
      context: .
      target: frankenphp_prod
    environment:
      APP_SECRET: ${APP_SECRET}
      MERCURE_PUBLISHER_JWT_KEY: ${CADDY_MERCURE_JWT_SECRET}
      MERCURE_SUBSCRIBER_JWT_KEY: ${CADDY_MERCURE_JWT_SECRET}

Add .env.prod.local:

SERVER_NAME=:80
APP_SECRET=ChangeMe
CADDY_MERCURE_JWT_SECRET=ChangeThisMercureHubJWTSecretKey

Now run: docker compose -f compose.yaml -f compose.prod.yaml up -d --wait

It will output:
WARN[0000] The "APP_SECRET" variable is not set. Defaulting to a blank string.
WARN[0000] The "CADDY_MERCURE_JWT_SECRET" variable is not set. Defaulting to a blank string.
WARN[0000] The "CADDY_MERCURE_JWT_SECRET" variable is not set. Defaulting to a blank string.
[+] Running 0/1

@maxhelias I guess it's enough. Because of that if I request the server it will always print phpinfo() output.

@7-zete-7
Copy link

@fleonardelli when you configure both env_file attribute and set the values of environment variables to be mandatory, Docker Compose will still warn about missing values for environment variables from the host, even if these values are already set in the env_file attribute file.

If there are required parameters in environment attribute, they will not be subtracted from the env_file attribute file. The values of environment variables are passed through to the container.

If you want to be able to convert environment variables (as is done in this template), then you must use the --env-file parameter or the COMPOSE_ENV_FILES environment variable when running the docker compose command.

The documentation page has a table of results when there are multiple sources for environment variable values. However, there is no example of what the result will be if both parameters are present (in attribute env_file and in attribute environment).

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

No branches or pull requests

3 participants