The following is the error content
terminal
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known (SQL: select * from information_schema.tables where table_schema = db_name and table_name = migrations and table_type = 'BASE TABLE')
at /var/www/html/laravel-vue-app/vendor/laravel/framework/src/Illuminate/Database/Connection.php:669
665| // If an exception occurs when attempting to run a query, we'll format the error
666| // message to include the bindings with SQL, which will make this exception a
667| // lot more helpful to the developer instead of just the database's errors.
668| catch (Exception $e) {
> 669| throw new QueryException(
670| $query, $this->prepareBindings($bindings), $e
671| );
672| }
673|
Exception trace:
1 PDOException::("PDO::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known")
/var/www/html/laravel-vue-app/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
2 PDO::__construct("mysql:host=mysql;port=3306;dbname=db_name", "db_user", "db_password", [])
/var/www/html/laravel-vue-app/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
Please use the argument -v to see more details.
In conclusion, docker-compose.yml and .env mysql settings must be the same
Check if .env under laravel (app /) exists-> Host name must be matched with docker container name Need to change if there is a difference in the contents of docker-compose.yml After the change
docker
docker-compose stop
docker-compose up -d
It is necessary to do Reason: restart doesn't reflect the docker-compose.yml settings If you want to reflect the setting of .env
terminal
php artisan config:cache
Need to be reflected in
Apparently the app container where laravel is billed-> the db container where mysql is built It seems that an error has occurred when communicating with each other, When communicating between docker containers, enter the IP address given to the container in which mysql is built. It is necessary to use
terminal
cat /etc/hosts | awk ‘END{print $1}’ | sed -r -e ‘s/[0-9]+$/1/g’
You can check the IP address of the container with You should check if the host IP of .env under app is the same.