Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Lena's avatar
Level 5

Changing value of DB_HOST in .env - Docker environment

I run my project using Laravel 8 and Docker.

When I am inside Docker container and run DB related artisan commands I must update my .env file with this:

DB_HOST=mysql (service name from docker-compose.yml)

If I leave it like that I will get error trying to access website on 127.0.0.0.1:8000 and to fix it I need to go back again to .env and change DB_HOST to:

DB_HOST=127.0.0.1

Is something missing in my docker-compose.yml file in order to avoid keep editing .env? What am I doing wrong?

docker-compose.yml: https://www.codepile.net/pile/M1V6Dk1q

Thanks!

0 likes
3 replies
sr57's avatar

I must update my .env file with this: DB_HOST=mysql

Yes, or pgsql if you use postgresql

Please correct your post to have a look to your setup, but the standard one works with this setting.

Lena's avatar
Level 5

Do you mean this is how it should be? Not really convenient. The file was generated by Laravel Sail so I have no idea what to change.

sr57's avatar

I compare your file versus mine, except the fact that I use postgresql I saw this difference :

<             context: ./vendor/laravel/sail/runtimes/8.0
---
>             context: ./docker/8.0

to create my project on linux I use this cde : curl -s https://laravel.build/example-app | bash

https://laravel.com/docs/8.x/installation#getting-started-on-linux

PS : what about your previous post 'Mix not found'?, if you found a solution by yourself, share it and close the thread.

Please or to participate in this conversation.