When I try to migrate after set up laradock I get this error:
I set up laradock following the main doc, everything works as it should but no when I create a new user from the browser.
IlluminateDatabaseQueryException : SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known (SQL: select * from information_schema.tables where table_schema = cd_eloquent and table_name = migrations and table_type = 'BASE TABLE')
at /Users/cristian/development/laravel/cd_eloquent/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: nodename nor servname provided, or not known")
/Users/cristian/development/laravel/cd_eloquent/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
2 PDO::__construct("mysql:host=mysql;port=3306;dbname=cd_eloquent", "cristian", "cristian", [])
/Users/cristian/development/laravel/cd_eloquent/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
Please use the argument -v to see more details.
.env
Example .env following the main doc using DB_HOST=mysql
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=cd_eloquent
DB_USERNAME=cristian
DB_PASSWORD=cristian
if I change my .env
I change the DB_HOST=127.0.0.1
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=cd_eloquent
DB_USERNAME=cristian
DB_PASSWORD=cristian
and then I get all the migrations
Only works with 127.0.0.1 no with mysql
cd_eloquent git:(master) ✗ php artisan migrate
Migration table created successfully.
Migrating: 2014_10_12_000000_create_users_table
Migrated: 2014_10_12_000000_create_users_table (0.04 seconds)
Migrating: 2014_10_12_100000_create_password_resets_table
Migrated: 2014_10_12_100000_create_password_resets_table (0.05 seconds)
Migrating: 2019_08_19_000000_create_failed_jobs_table
Migrated: 2019_08_19_000000_create_failed_jobs_table (0.08 seconds)
When I try to signup, I get this error
if I change my .env
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=cd_eloquent
DB_USERNAME=cristian
DB_PASSWORD=cristian
I get this error
What is wrong here?
laradock .env
### MYSQL #################################################
MYSQL_VERSION=5.7
MYSQL_DATABASE=default
MYSQL_USER=default
MYSQL_PASSWORD=secret
MYSQL_PORT=3306
MYSQL_ROOT_PASSWORD=root
MYSQL_ENTRYPOINT_INITDB=./mysql/docker-entrypoint-initdb.d
laradock sites
Example of site
server {
listen 80;
listen [::]:80;
# For https
# listen 443 ssl;
# listen [::]:443 ssl ipv6only=on;
# ssl_certificate /etc/nginx/ssl/default.crt;
# ssl_certificate_key /etc/nginx/ssl/default.key;
server_name cd_eloquent.test;
root /var/www/cd_eloquent/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ .php$ {
try_files $uri /index.php =404;
fastcgi_pass php-upstream;
fastcgi_index index.php;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fixes timeouts
fastcgi_read_timeout 600;
include fastcgi_params;
}
location ~ /.ht {
deny all;
}
location /.well-known/acme-challenge/ {
root /var/www/letsencrypt/;
log_not_found off;
}
error_log /var/log/nginx/laravel_error.log;
access_log /var/log/nginx/laravel_access.log;
}
Example phpmyadmin
Example of containers running
Docker-compose ps
Another example
DB_CONNECTION=mysql
DB_HOST=laradock_mysql
DB_PORT=3306
DB_DATABASE=cd_eloquent
DB_USERNAME=cristian
4
Answers
just retry
php artisan migrate:fresh
from your laradock workspace container it will work.ex:
docker-compose exec workspace bash
php artisan migrate:fresh
Sometimes you had to change the DB_HOST on
.env
In my case the IP was changed and the migrations run on my computer but not in the container which has another IP.On laradock each service has its own container thus localhost or 127.0.0.1 refers to the workspace container that doesn’t have mysql in it, try:
This would map the correct internal ip address using Docker’s internal nameserver.
On laradock, if you’re using mariadb instead of mysql use mariadb as the DB_HOST.
DB_HOST=mariadb