Skip to content
Advertisement

Docker – Nginx, PHP, MySQL – Laravel artisan migrate connection refused

I have Laravel running in Docker with 3 containers – Nginx, MySQL 8 And PHP 8.

I have the following docker-compose.yaml

JavaScript

This command:

JavaScript

Launches 3 containers:

JavaScript

I want to run php artisan migrate, so I try it like so:

JavaScript

This gives me the following error:

JavaScript

My mysql.env file is like so:

JavaScript

AND .env:

JavaScript

I’ve tried changing ports, host, but I just can’t get access – I must have messed something up somewhere.

Advertisement

Answer

In my haste, I was trying to run commands before mysql was ready. It can take 90 seconds after a rebuild for the container to accept connections.

JavaScript

Once it was ready to connect, my commands would run.

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