I like using Docker for my Laravel apps, but I typically use it directly without Laravel Sail.
On a recent client project, they were using Sail and I bumped into two env-related issues that I wanted to share.
First, even though Sail is based on Docker, I would get warnings if I tried to interact with the Docker images directly using Docker commands.
For example, running sail up gave no warnings, but I'd see this if I ran docker compose up -d:
WARN[0000] The "WWWUSER" variable is not set. Defaulting to a blank string.
WARN[0000] The "WWWGROUP" variable is not set. Defaulting to a blank string.
These warnings were annoying, but the containers worked just fine as far as I could tell.
The issue is that the vendor/bin/sail script injects a number of environment variables which the underlying Docker files expect to be present.
When they aren't set, Docker emits this warning.
The solution is simple: just use Sail commands instead of Docker commands directly. Or if you want to use Docker directly (perhaps your IDE has built-in Docker support), just set those env vars yourself when setting up that integration.
The other env-related issue on this project was a similar warning, but it was happening for a different reason:
WARN[0000] The "DB_HOST" variable is not set. Defaulting to a blank string.
This warning would happen only when using the sail command, not when running Docker commands directly.
The problem was the project's .env file had some invalid syntax.
There was a nested variable referring to DB_HOST, but this project had DB_HOST_READ and DB_HOST_WRITE instead of DB_HOST.
The sail command sources the .env file as part of execution, so any syntax errors in that file would emit warnings like this.
The solution was simple: fix the .env file to remove the invalid reference.
Here to help,
Joel
P.S. Want some help reviewing your Laravel code for performance issues? Let's talk.