Skip to content
Advertisement

Docker + Laravel issue – “ViewException”

docker-compose.yml:

JavaScript

default.conf:

JavaScript

Dockerfile:

JavaScript

.env file:

JavaScript

I’m trying to run laravel application and I can tell for sure that database is working properly, .env file configuration is correct and application installation goes successfully (installation does database connection and creates all necessary tables correctly with correct default data inside them)

App works perfectly outside Docker container on Windows machine, problem emerges inside Docker container . My Docker uses linux containers. After reading laravel.log I see that ViewException gets thrown and none of the view files are loaded inside browser (instead I get 404 on homepage, on login page I get the exception which can be seen on screenshot below)

login page

I guess that app doesn’t resolve correct path for view files and my question is if anyone here knows what could be causing this problem?

Advertisement

Answer

Short

Update DB_HOST in .env

JavaScript

More about that

In your .env file the hostname for your database is localhost

JavaScript

The reason it’s working locally is because you exposed 3306 from docker to the host machine 3306

But both containers can access each other in internal docker network by using their docker hostname which is mysql based on your docker-compose file

Another solution but I don’t recommend it (Because since the mysql is already in the same stack no need to connect to host then go back to the mysql container since containers can access each other directly without using port exposed on host, and you can actually stop exposing this port later and it’ll still work between the two containers)

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement