前提
php artisan migrateを実行した際に以下のようなエラーが起きました。
Illuminate\Database\QueryException SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for mysql failed: nodename nor servname provided, or not known (SQL: select * from information_schema.tables where table_schema = laravel and table_name = migrations and table_type = 'BASE TABLE') at vendor/laravel/framework/src/Illuminate/Database/Connection.php:745 741▕ // If an exception occurs when attempting to run a query, we'll format the error 742▕ // message to include the bindings with SQL, which will make this exception a 743▕ // lot more helpful to the developer instead of just the database's errors. 744▕ catch (Exception $e) { ➜ 745▕ throw new QueryException( 746▕ $query, $this->prepareBindings($bindings), $e 747▕ ); 748▕ } 749▕ } +33 vendor frames 34 artisan:37 Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
実現したいこと
migrationを通したい
発生している問題・エラーメッセージ
Illuminate\Database\QueryException SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for mysql failed: nodename nor servname provided, or not known (SQL: select * from information_schema.tables where table_schema = laravel and table_name = migrations and table_type = 'BASE TABLE') at vendor/laravel/framework/src/Illuminate/Database/Connection.php:745 741▕ // If an exception occurs when attempting to run a query, we'll format the error 742▕ // message to include the bindings with SQL, which will make this exception a 743▕ // lot more helpful to the developer instead of just the database's errors. 744▕ catch (Exception $e) { ➜ 745▕ throw new QueryException( 746▕ $query, $this->prepareBindings($bindings), $e 747▕ ); 748▕ } 749▕ } +33 vendor frames 34 artisan:37 Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
該当のソースコード
docker-compose.yml
version: '3' services: db: image: mysql:8.0.28-debian command: mysqld --default-authentication-plugin=mysql_native_password --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci environment: MYSQL_ROOT_PASSWORD: password MYSQL_DATABASE: laravel MYSQL_USER: laravel MYSQL_PASSWORD: password expose: - 3306 ports: - 3306:3306 volumes: - ./data:/var/lib/mysql
APP_NAME=Laravel APP_ENV=local APP_KEY=base64:pO8LmIWCG+hV/iKiw7gbu85sAV6rxiDCp10hMeKu2gE= APP_DEBUG=true APP_URL=http://localhost LOG_CHANNEL=stack LOG_DEPRECATIONS_CHANNEL=null LOG_LEVEL=debug DB_CONNECTION=mysql DB_HOST=mysql DB_PORT=3306 DB_DATABASE=laravel DB_USERNAME=laravel DB_PASSWORD=password BROADCAST_DRIVER=log CACHE_DRIVER=file FILESYSTEM_DISK=local QUEUE_CONNECTION=sync SESSION_DRIVER=file SESSION_LIFETIME=120 MEMCACHED_HOST=127.0.0.1 REDIS_HOST=127.0.0.1 REDIS_PASSWORD=null REDIS_PORT=6379 MAIL_MAILER=smtp MAIL_HOST=mailhog MAIL_PORT=1025 MAIL_USERNAME=null MAIL_PASSWORD=null MAIL_ENCRYPTION=null MAIL_FROM_ADDRESS="hello@example.com" MAIL_FROM_NAME="${APP_NAME}" AWS_ACCESS_KEY_ID= AWS_SECRET_ACCESS_KEY= AWS_DEFAULT_REGION=us-east-1 AWS_BUCKET= AWS_USE_PATH_STYLE_ENDPOINT=false PUSHER_APP_ID= PUSHER_APP_KEY= PUSHER_APP_SECRET= PUSHER_APP_CLUSTER=mt1 MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
試したこと
キャッシュクリア
docker-compose down --volumes php artisan config:cache php artisan cache:clear
補足情報(FW/ツールのバージョンなど)
mysql Ver 14.14 Distrib 5.7.37, for osx10.16 (x86_64) using EditLine wrapper PHP 8.1.5 Laravel Installer 4.2.10

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。