Git Product home page Git Product logo

Comments (4)

7-zete-7 avatar 7-zete-7 commented on July 29, 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/).

from symfony-docker.

maxhelias avatar maxhelias commented on July 29, 2024

Can you provide a reproducer pls ?

from symfony-docker.

fleonardelli avatar fleonardelli commented on July 29, 2024

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.

from symfony-docker.

7-zete-7 avatar 7-zete-7 commented on July 29, 2024

@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).

from symfony-docker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.