Having issues passing environment variables to Laravel #82
-
Hey guys! I'm having an issue passing environment vars into the container which is causing migrations to fail. I'm building a new image based on FROM serversideup/php:beta-8.1-fpm-nginx
ENV PHP_POOL_NAME=speedtest-tracker_php
ENV PHP_POST_MAX_SIZE=1G
ENV PHP_UPLOAD_MAX_FILE_SIZE=1G
# Install addition packages
RUN apt-get update && apt-get install -y \
cron \
gnupg \
php8.1-pgsql \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
# Install Speedtest cli
RUN curl -s https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh | bash \
&& apt-get install -y speedtest
# Copy package configs
COPY --chmod=644 docker/deploy/cron/scheduler /etc/cron.d/scheduler
COPY --chmod=755 docker/deploy/etc/s6-overlay/ /etc/s6-overlay/
# Copy app
COPY . /var/www/html
COPY .env.docker .env
# Install app dependencies
RUN composer install --no-interaction --prefer-dist --optimize-autoloader --no-dev \
&& mkdir -p /app \
&& mkdir -p storage/logs \
&& php artisan optimize:clear \
&& chown -R webuser:webgroup /var/www/html \
&& crontab /etc/cron.d/scheduler During this build I'm copying a Laravel docker run -d --name speedtest-tracker \
-e "DB_CONNECTION=mysql" \
-e "DB_HOST=host.docker.internal" \
-e "DB_PORT=3306" \
-e "DB_DATABASE=speedtest_tracker" \
-e "DB_USERNAME=root" \
-e "DB_PASSWORD=password" \
-v /path/to/app/_data:/app \
speedtest-tracker Laravel doesn't seem to be seeing any of the vars I'm passing into the container, any help would be greatly appreciated! Reference issue and full code: alexjustesen/speedtest-tracker#41 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
I spent my morning diving in deep to see if I could replicate this. Long story short, I unfortunately could not get it to replicate. What I did
🎥 See the video demoing thishttps://www.dropbox.com/s/t2oucxf6mxxxi9r/LaravelEnvTest.mp4?dl=0 My Source codeAll accessible here: https://github.com/jaydrogers/laravel-env-test My gut feelingWithout diving into your app too deep, the only thing that threw me off guard was this: # Copy app
COPY .env.docker .env Theoretically that should work, but I was not able to replicate the issue in a blank laravel install. Take a look at this and let me know your thoughts and if you have any more questions! |
Beta Was this translation helpful? Give feedback.
-
Whoa dude, this was SUPER HELPFUL! All that effort in isolating it to a brand new Laravel install paid off troubleshooting this. How I was able to replicateOnce I added the auto migrations, then I was able to replicate the issue: jaydrogers/laravel-env-test@4438f2d?short_path=b335630#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5 The problemIn my script, I had a The SolutionI just pushed a commit (b0716db) that utilizes the Next StepsTry again with the latest beta image, and this should work for you 👍 Thanks for testing out my new images 🙌 |
Beta Was this translation helpful? Give feedback.
Whoa dude, this was SUPER HELPFUL!
All that effort in isolating it to a brand new Laravel install paid off troubleshooting this.
How I was able to replicate
Once I added the auto migrations, then I was able to replicate the issue: jaydrogers/laravel-env-test@4438f2d?short_path=b335630#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5
The problem
In my script, I had a
su - webuser
in my"laravel-automations" script, which was running commands aswebuser
but not passing the environment variables from the container 🙃The Solution
I just pushed a commit (b0716db) that utilizes the
s6-setuidgid
command, which properly passes the environment and switches users "The S6 Way".N…