Laravel Sail: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for mysql failed: Temporary failure in name resolution
Commands run outside the Sail container (on the host) try to resolve the Docker service name mysql, which only exists inside the Docker network.
php_network_getaddresses: getaddrinfo for mysql failed: Temporary failure in name resolutiongetaddrinfo for mysql failed: Name or service not knownSQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known (sail)Sail mysql host not found Meaning
Run artisan inside the container: ./vendor/bin/sail artisan migrate. If you want to run from the host, set DB_HOST=127.0.0.1 and use the forwarded port (FORWARD_DB_PORT). Also make sure containers are up (sail up -d) and MySQL finished initialising.
Common causes
- Running
php artisan migrateon the host withDB_HOST=mysql - Containers not started
- MySQL container still booting
- Port conflicts (3306 already used)
- Wrong network
⚡ Quick fix
- Use
./vendor/bin/sail artisan ... - Or set
DB_HOST=127.0.0.1for host commands ./vendor/bin/sail up -dand wait for health
Detailed fix by platform
Docker
./vendor/bin/sail up -d && ./vendor/bin/sail artisan migrate
How to diagnose
- Where — Host or container?
- DB_HOST — Service name vs localhost?
- Containers — Running?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- 403 This action is unauthorized Laravel: Illuminate\Auth\Access\AuthorizationException: This action is unauthorized.
- Attempt to read property "x" on null Laravel/PHP 8: ErrorException: Attempt to read property "name" on null
- Command "x" is not defined Laravel: Symfony\Component\Console\Exception\CommandNotFoundException: Command "make:livewire" is not defined. Did you mean one of these?
Most viewed in Laravel
- MassAssignmentException Laravel: Illuminate\Database\Eloquent\MassAssignmentException: Add [x] to fillable property to allow mass assignment
- The GET method is not supported for route Laravel: The GET method is not supported for route x. Supported methods: POST (MethodNotAllowedHttpException)
- Route [login] not defined Laravel: Symfony\Component\Routing\Exception\RouteNotFoundException: Route [login] not defined
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 4 Nov 2026