Hope you are well,
I have a project that I recently upgraded to laravel 8 from laravel 6.
it was dockerized both for dev and prod, after update unfortunately the app does not retrieve the env values that are passed by the docker-compose file and only works if I pass a .env file to the container.
this is while, inside the container I can still do:
php artisan tinker
>> print_r(env("DB_HOST"))
&& print_r($_ENV)
and see the env values even without passing the file itself
so the compose file passes the env values to the container but the laravel app does not pick them up
has anyone else faced this issue with laravel 8?
Thank you in advance,
This could be a caching issue. Please also make sure to access all env variables through config()
calls and not to env()
directly - that won't resolve if you're caching config.
This is the entrypoint script I'm using for production laravel images:
#!/bin/sh
artisan="/usr/local/bin/php /var/www/artisan"
$artisan down
$artisan cache:clear
$artisan config:clear
$artisan config:cache
$artisan event:clear
$artisan event:cache
$artisan route:clear
$artisan view:clear
$artisan up
apache2-foreground
This clears all caches and caches them again when starting the container to ensure all values are up to date after a restart.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With