Open fleonardelli opened 2 months ago
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/).
Can you provide a reproducer pls ?
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.
@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
).
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:
So now instead of running:
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.localI can't figure out how to make it pick up .env.prod.local.