guillaumebriday / todolist-backend-laravel

Back-end application for Todolist Web application built with Laravel 5.8 and Vue.js
https://todolist-docs.guillaumebriday.me
MIT License
70 stars 22 forks source link

php_network_getaddresses: getaddrinfo failed: Name or service not known #7

Closed marketinghubai closed 5 years ago

marketinghubai commented 5 years ago

Hi all! If I am running "docker-compose run --rm todolist-server php artisan migrate" command, I got this error:

Illuminate\Database\QueryException : SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known (SQL: select * from information_schema.tables where table_schema = laravel-todolist and table_name = migrations)

I assume, I need to add "mysql" to /etc/hosts, however If I do so, I got also an error:

SQLSTATE[HY000] [1130] Host '172.18.0.6' is not allowed to connect to this MySQL server or (IP: 127.0.0.1) SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known

guillaumebriday commented 5 years ago

Hey ! Nope you don't need to add anything to your /etc/hosts because it's handle inside a Docker network.

I think you got this error because your MySQL container did not finish to start before Laravel tried to migrate. Try to run it again with mysql, this should work as expected

marketinghubai commented 5 years ago

HI! Thak you for your answer! In this case I don't know what ca be wrong. I did everything from the beginning, but there is an error again: [root@todo www]# git clone https://github.com/guillaumebriday/todolist-backend-laravel.git Cloning into 'todolist-backend-laravel'... remote: Enumerating objects: 75, done. remote: Counting objects: 100% (75/75), done. remote: Compressing objects: 100% (60/60), done. remote: Total 1216 (delta 17), reused 38 (delta 10), pack-reused 1141 Receiving objects: 100% (1216/1216), 418.20 KiB | 0 bytes/s, done. Resolving deltas: 100% (581/581), done. [root@todo www]# nano /etc/hosts [root@todo www]# cd todolist-backend-laravel [root@todo todolist-backend-laravel]# cp .env.example .env [root@todo todolist-backend-laravel]# docker-compose run --rm --no-deps todolist-server composer install Deprecation warning: Your package name Todolist Backend is invalid, it should have a vendor name, a forward slash, and a package name. The vendor and package name can be words separated by -, . or . The complete name should match "[a-z0-9]([.-]?[a-z0-9]+)/a-z0-9". Make sure you fix this as Composer 2.0 will error. Do not run Composer as root/super user! See https://getcomposer.org/root for details Loading composer repositories with package information Installing dependencies (including require-dev) from lock file Package operations: 101 installs, 0 updates, 0 removals

jwt-auth secret [i3omzNv5GJXSdIxiK0vzavQ0CANnlrBY] set successfully. [root@todo todolist-backend-laravel]# docker-compose up -d Starting todolist-backend-laravel_mysql-test_1 ... done Starting todolist-backend-laravel_mysql_1 ... done todolist-backend-laravel_todolist-server_1 is up-to-date todolist-backend-laravel_nginx_1 is up-to-date [root@todo todolist-backend-laravel]# docker-compose run --rm todolist-server php artisan migrate Starting todolist-backend-laravel_mysql-test_1 ... done Starting todolist-backend-laravel_mysql_1 ... done

Illuminate\Database\QueryException : SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known (SQL: select * from information_schema.tables where table_schema = laravel-todolist and table_name = migrations)

at /var/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664 660| // If an exception occurs when attempting to run a query, we'll format the error 661| // message to include the bindings with SQL, which will make this exception a 662| // lot more helpful to the developer instead of just the database's errors. 663| catch (Exception $e) {

664| throw new QueryException( 665| $query, $this->prepareBindings($bindings), $e 666| ); 667| } 668|

Exception trace:

1 PDOException::("PDO::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known") /var/www/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70

2 PDO::__construct("mysql:host=mysql;port=3306;dbname=laravel-todolist", "root", "secret", []) /var/www/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70

Please use the argument -v to see more details. [root@todo todolist-backend-laravel]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 23c6e921bb92 nginx "nginx -g 'daemon of…" 18 hours ago Up 18 hours 80/tcp, 0.0.0.0:8000->8000/tcp todolist-backend-laravel_nginx_1 9c84dbe24770 todolist-backend "docker-php-entrypoi…" 18 hours ago Up 18 hours 9000/tcp todolist-backend-laravel_todolist-server_1 d5c202d0e4fc mysql:8 "docker-entrypoint.s…" 18 hours ago Up 24 seconds 33060/tcp, 0.0.0.0:3307->3306/tcp todolist-backend-laravel_mysql-test_1 [root@todo todolist-backend-laravel]#

guillaumebriday commented 5 years ago

Hum I think it's because mysql did not boot up before php starts its migration

Retry the last command it should work

diegosistem09 commented 3 years ago

Buen dia tengo un problema de conexion desde mi entorno dev SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution ya verifique el archivo .env y esta correcto con las credenciales correctas no se que mas pueda ser por favor alguien que me pueda dar una guia. gracias

guillaumebriday commented 3 years ago

English only please @diegosistem09

diegosistem09 commented 3 years ago

Good morning I have a connection problem from my dev environment SQLSTATE [HY000] [2002] php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution I already verified the .env file and it is correct with the correct credentials I do not know what else it could be someone please that you can give me a guide. Thank you