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

Haseeb69's avatar

sql errors on laravel docker

i wanted to dockerize my laravel app. However laravel sail does not explain in any way how to configure your database after running migrations . Anways i gave up on sail as followed some tutorials

i launched two containers of mysql and php like this

sudo docker pull mysql/mysql-server:latest
sudo docker run --name=mysql  -e MYSQL_ROOT_PASSWORD=mypass -d mysql/mysql-server:latest

sudo docker pull phpmyadmin/phpmyadmin:latest
sudo docker run --name phpmyadmin -d --link mysql:db -p 8081:80 phpmyadmin/phpmyadmin

so i configured my user and imported my db manually in phpmyadmin

i launch my laravel container using my docker file etc

#some other code ...
EXPOSE 8000
CMD php artisan serve --host=0.0.0.0 --port=8000

my env file

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:aS838/4/6V7n9VQXDUdiQBDxDiM7sWhSc1ym0KahcZY=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack
LOG_LEVEL=debug

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=mydb
DB_USERNAME=root
DB_PASSWORD=mypass

if i keep db_host as 127.0.0.1 i get connection refused error if i give db_host as mysql(which is my running mysql container name) i get pdo errors if i give db_host as localhost i get not found errors i saw on few stackoverflow fixes that u have to give your local network ips instead i dont wanna do it cause i have my own reasons any way around this? i'm stuck on this for 2 days now and im depressed af .any help will be appreciated

0 likes
5 replies
Haseeb69's avatar

Is there anyway to solve my problem apart from using sail bro?

neilstee's avatar
neilstee
Best Answer
Level 34

@haseeb69 oops, sorry I thought you are having a problem in your Sail with your DB. ignore my solution above.

If you followed this I think you should be good to go: https://laravel.com/docs/8.x/sail#installing-sail-into-existing-applications

However laravel sail does not explain in any way how to configure your database after running migrations

Whatever you put in your .env, Sail will just copy that and provides a database for you with that exact credentials so you don't need to worry about anything.

Let me know if you still having a hard time. Happy to help.

1 like
Haseeb69's avatar

thanks bro a simple explanation just solved my concerns i configured sail with phpmyadmin and i found a better approach

1 like

Please or to participate in this conversation.