Connection refused when running Laravel artisan command with Docker
First edit your docker-compose.yml
.
mysql: image: mariadb:latest ports: - 8889:3306
After that set the correct DB port in .env
.
Your DB port is wrong. You are trying to connect the exposed port inside the docker. In this case you should use DB_PORT=3306
in your .env
.
this worked for me:put the name of my mysql container instead of 127.0.0.1
NAME CONTAINERSproject-db --> container mysqlproject-app --> container laravelDB_CONNECTION=mysqlDB_HOST=project-dbDB_PORT=3306DB_DATABASE=projectDB_USERNAME=rootDB_PASSWORD=root
Try change port to 3306 and use DB_HOST=localhost to yourdomain.com(your IP)
And don't forget Sudo Clear cache and config cache
DB_HOST=My_ip_for_virtual_machine (yourdomain.com)sudo docker-compose exec app php artisan config:clearsudo docker-compose exec app php artisan cache:clear