質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
docker-compose

docker-composeとは、複数のコンテナで構成されるサービスを提供する手順を自動的し管理を簡単にするツール。composeファイルを使用しコマンド1回で設定した全サービスを作成・起動することが可能です。

Laravel

LaravelとはTaylor Otwellによって開発された、オープンソースなPHPフレームワークです。Laravelはシンプルで表現的なシンタックスを持ち合わせており、ウェブアプリケーション開発の手助けをしてくれます。

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

Docker

Dockerは、Docker社が開発したオープンソースのコンテナー管理ソフトウェアの1つです

Q&A

2回答

2080閲覧

php artisan migrateの際にエラーが起きる

fukusyun1

総合スコア6

docker-compose

docker-composeとは、複数のコンテナで構成されるサービスを提供する手順を自動的し管理を簡単にするツール。composeファイルを使用しコマンド1回で設定した全サービスを作成・起動することが可能です。

Laravel

LaravelとはTaylor Otwellによって開発された、オープンソースなPHPフレームワークです。Laravelはシンプルで表現的なシンタックスを持ち合わせており、ウェブアプリケーション開発の手助けをしてくれます。

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

Docker

Dockerは、Docker社が開発したオープンソースのコンテナー管理ソフトウェアの1つです

0グッド

0クリップ

投稿2022/04/24 12:53

編集2022/04/29 15:05

前提

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

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

回答ありがとうございます!

php artisan migrate Illuminate\Database\QueryException SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for db 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))

やはりエラー起きてしまいますね

投稿2022/04/29 06:04

fukusyun1

総合スコア6

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

.envのDB_HOST=mysqlをDB_HOST=dbにするといかがでしょうか?

投稿2022/04/25 08:45

bz0

総合スコア4

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

fukusyun1

2022/04/29 06:05

回答ありがとうございます! ``` php artisan migrate Illuminate\Database\QueryException SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for db 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)) ``` やはりエラー起きてしまいますね
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問