Closed marketinghubai closed 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
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
Installing phpunit/phpunit (7.5.6): Downloading (100%)
symfony/var-dumper suggests installing ext-intl (To show region name in time zone dump)
symfony/routing suggests installing symfony/config (For using the all-in-one router or any loader)
symfony/routing suggests installing symfony/dependency-injection (For loading routes from a service)
symfony/routing suggests installing symfony/expression-language (For using expression matching)
symfony/routing suggests installing symfony/yaml (For using the YAML loader)
symfony/contracts suggests installing psr/cache (When using the Cache contracts)
symfony/contracts suggests installing symfony/cache-contracts-implementation
symfony/contracts suggests installing symfony/service-contracts-implementation
symfony/event-dispatcher suggests installing symfony/dependency-injection
symfony/http-kernel suggests installing symfony/browser-kit
symfony/http-kernel suggests installing symfony/config
symfony/http-kernel suggests installing symfony/dependency-injection
symfony/console suggests installing symfony/lock
egulias/email-validator suggests installing ext-intl (PHP Internationalization Libraries are required to use the SpoofChecking validation)
swiftmailer/swiftmailer suggests installing ext-intl (Needed to support internationalized email addresses)
swiftmailer/swiftmailer suggests installing true/punycode (Needed to support internationalized email addresses, if ext-intl is not installed)
paragonie/random_compat suggests installing ext-libsodium (Provides a modern crypto API that can be used to generate random bytes.)
ramsey/uuid suggests installing ext-libsodium (Provides the PECL libsodium extension for use with the SodiumRandomGenerator)
ramsey/uuid suggests installing ext-uuid (Provides the PECL UUID extension for use with the PeclUuidTimeGenerator and PeclUuidRandomGenerator)
ramsey/uuid suggests installing ircmaxell/random-lib (Provides RandomLib for use with the RandomLibAdapter)
ramsey/uuid suggests installing moontoast/math (Provides support for converting UUID to 128-bit integer (in string form).)
ramsey/uuid suggests installing ramsey/uuid-console (A console application for generating UUIDs with ramsey/uuid)
ramsey/uuid suggests installing ramsey/uuid-doctrine (Allows the use of Ramsey\Uuid\Uuid as Doctrine field type.)
symfony/translation suggests installing symfony/config
symfony/translation suggests installing symfony/yaml
monolog/monolog suggests installing aws/aws-sdk-php (Allow sending log messages to AWS services like DynamoDB)
monolog/monolog suggests installing doctrine/couchdb (Allow sending log messages to a CouchDB server)
monolog/monolog suggests installing ext-amqp (Allow sending log messages to an AMQP server (1.0+ required))
monolog/monolog suggests installing ext-mongo (Allow sending log messages to a MongoDB server)
monolog/monolog suggests installing graylog2/gelf-php (Allow sending log messages to a GrayLog2 server)
monolog/monolog suggests installing mongodb/mongodb (Allow sending log messages to a MongoDB server via PHP Driver)
monolog/monolog suggests installing php-amqplib/php-amqplib (Allow sending log messages to an AMQP server using php-amqplib)
monolog/monolog suggests installing php-console/php-console (Allow sending log messages to Google Chrome)
monolog/monolog suggests installing rollbar/rollbar (Allow sending log messages to Rollbar)
monolog/monolog suggests installing ruflin/elastica (Allow sending log messages to an Elastic Search server)
monolog/monolog suggests installing sentry/sentry (Allow sending log messages to a Sentry server)
league/flysystem suggests installing league/flysystem-aws-s3-v2 (Allows you to use S3 storage with AWS SDK v2)
league/flysystem suggests installing league/flysystem-aws-s3-v3 (Allows you to use S3 storage with AWS SDK v3)
league/flysystem suggests installing league/flysystem-azure (Allows you to use Windows Azure Blob storage)
league/flysystem suggests installing league/flysystem-cached-adapter (Flysystem adapter decorator for metadata caching)
league/flysystem suggests installing league/flysystem-eventable-filesystem (Allows you to use EventableFilesystem)
league/flysystem suggests installing league/flysystem-rackspace (Allows you to use Rackspace Cloud Files)
league/flysystem suggests installing league/flysystem-sftp (Allows you to use SFTP server storage via phpseclib)
league/flysystem suggests installing league/flysystem-webdav (Allows you to use WebDAV storage)
league/flysystem suggests installing league/flysystem-ziparchive (Allows you to use ZipArchive adapter)
league/flysystem suggests installing spatie/flysystem-dropbox (Allows you to use Dropbox storage)
league/flysystem suggests installing srmklive/flysystem-dropbox-v2 (Allows you to use Dropbox storage for PHP 5 applications)
laravel/framework suggests installing aws/aws-sdk-php (Required to use the SQS queue driver and SES mail driver (^3.0).)
laravel/framework suggests installing doctrine/dbal (Required to rename columns and drop SQLite columns (^2.6).)
laravel/framework suggests installing ext-pcntl (Required to use all features of the queue worker.)
laravel/framework suggests installing league/flysystem-aws-s3-v3 (Required to use the Flysystem S3 driver (^1.0).)
laravel/framework suggests installing league/flysystem-cached-adapter (Required to use the Flysystem cache (^1.0).)
laravel/framework suggests installing league/flysystem-rackspace (Required to use the Flysystem Rackspace driver (^1.0).)
laravel/framework suggests installing league/flysystem-sftp (Required to use the Flysystem SFTP driver (^1.0).)
laravel/framework suggests installing moontoast/math (Required to use ordered UUIDs (^1.1).)
laravel/framework suggests installing nexmo/client (Required to use the Nexmo transport (^1.0).)
laravel/framework suggests installing pda/pheanstalk (Required to use the beanstalk queue driver (^4.0).)
laravel/framework suggests installing predis/predis (Required to use the redis cache and queue drivers (^1.0).)
laravel/framework suggests installing symfony/dom-crawler (Required to use most of the crawler integration testing tools (^4.2).)
laravel/framework suggests installing symfony/psr-http-message-bridge (Required to use PSR-7 bridging features (^1.1).)
laravel/framework suggests installing wildbit/swiftmailer-postmark (Required to use Postmark mail driver (^3.0).)
psy/psysh suggests installing ext-pcntl (Enabling the PCNTL extension makes PsySH a lot happier :))
psy/psysh suggests installing ext-pdo-sqlite (The doc command requires SQLite to work.)
psy/psysh suggests installing hoa/console (A pure PHP readline implementation. You'll want this if your PHP install doesn't already support readline or libedit.)
paragonie/sodium_compat suggests installing ext-libsodium (PHP < 7.0: Better performance, password hashing (Argon2i), secure memory management (memzero), and better security.)
namshi/jose suggests installing phpseclib/phpseclib (Allows to use Phpseclib as crypto engine, use version ^2.0.)
lcobucci/jwt suggests installing mdanter/ecc (Required to use Elliptic Curves based algorithms.)
friendsofphp/php-cs-fixer suggests installing php-cs-fixer/phpunit-constraint-isidenticalstring (For IsIdenticalString constraint.)
friendsofphp/php-cs-fixer suggests installing php-cs-fixer/phpunit-constraint-xmlmatchesxsd (For XmlMatchesXsd constraint.)
filp/whoops suggests installing whoops/soap (Formats errors as SOAP responses)
sebastian/global-state suggests installing ext-uopz ()
phpunit/php-code-coverage suggests installing ext-xdebug (^2.6.0)
phpunit/phpunit suggests installing ext-soap ()
phpunit/phpunit suggests installing ext-xdebug (*)
phpunit/phpunit suggests installing phpunit/php-invoker (^2.0)
Generating optimized autoload files
Illuminate\Foundation\ComposerScripts::postAutoloadDump @php artisan package:discover Discovered Package: beyondcode/laravel-dump-server Discovered Package: fideloper/proxy Discovered Package: laravel/slack-notification-channel Discovered Package: laravel/tinker Discovered Package: nesbot/carbon Discovered Package: nunomaduro/collision Discovered Package: spatie/laravel-backup Discovered Package: spatie/laravel-cors Discovered Package: spatie/laravel-tail Discovered Package: tymon/jwt-auth Package manifest generated successfully. [root@todo todolist-backend-laravel]# docker-compose run --rm --no-deps todolist-server php artisan key:generate Application key set successfully. [root@todo todolist-backend-laravel]# docker-compose run --rm --no-deps todolist-server php artisan jwt:secret
This will invalidate all existing tokens. Are you sure you want to override the secret key? (yes/no) [no]:
yes
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]#
Hum I think it's because mysql did not boot up before php starts its migration
Retry the last command it should work
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
English only please @diegosistem09
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
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