Giter VIP home page Giter VIP logo

symfony-docker's Introduction

Run composer:

composer install

Build container:

# build container
docker build -t symfony-docker .

Check container env vars inside docker with .env file being passed:

docker run -it --rm -v "$PWD":/app --env-file=.env -w "/app" symfony-docker sh -c "bin/console debug:container --env-vars"

In EnvVarProcessor.php line 183:

Invalid JSON in env var "APP_JSON": Syntax error

and without passing .env file:

docker run -it --rm -v "$PWD":/app -w "/app" symfony-docker sh -c "bin/console debug:container --env-vars"

Symfony Container Environment Variables


Name Default value Real value


APP_JSON n/a "{"a":1}"
APP_SECRET n/a "cb4b2a7cbe10bc3d00659f42c67955f7"


The problem is parsing .env by docker, so making APP_JSON='{"a":1}' to be APP_JSON={"a":1} works for docker, but wouldn't work in console:

docker run -it --rm -v "$PWD":/app --env-file=.env -p 8000:8000 -w "/app" symfony-docker sh -c "echo \$APP_JSON"

'{"a":1}'

When replacing APP_JSON='{"a":1}' with APP_JSON={"a":1} it is the opposite - no error when passing .env, error if .env is ready by Symfony.

sed -i -e 's/APP_JSON=.*/APP_JSON={"a":1}/' .env

(OPTIONAL) Uncomment lines in Dockerfile and run the below to see WEB errors:

# run symfony
docker run -it --rm -v "$PWD":/app --env-file=.env -p 8000:8000 -w "/app" symfony-docker sh -c "/root/.symfony/bin/symfony server:start"

Now check http://127.0.0.1:8000/ and see the following error:

Cannot resolve argument $appJson of "App\Controller\DefaultController::index()": Invalid JSON in env var "APP_JSON": Syntax error

But when avoiding setting env vars in docker from .env, file is parsed by DotEnv and all works fine:

docker run -it --rm -v "$PWD":/app -p 8000:8000 -w "/app" symfony-docker sh -c "/root/.symfony/bin/symfony server:start"

symfony-docker's People

Contributors

jlekowski avatar

Watchers

 avatar

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.