Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php artisan migrate error: nodename nor servname provided or not know

I'm in trouble with my laradock project: i have downloaded and installed docker and i have successfully completed the setup of my laravel project with laradock. I use php 7, laravel(5.5.14) and the latest version of laradock. I start my project writing in shell:

docker-compose up -d nginx mysql

and all services starts. My env file is:

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=root
DB_PASSWORD=root

But when i try to use the migration with

php artisan migrate

i receive this error:

SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known (SQL: select * from information_schema.tables where table_schema = homestead and table_name = migrations) 
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known 
PDO::__construct(): php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known 

My db called homestead is created and it works. In my laravel project, under the migration folder i have 3 files php: create_user_table, create_password_reset_table and create_customer_table( i have wrote this file). I need to create a table in my db called customer with some colums:

Schema::create('customers', function (Blueprint $table) {
        $table->increments('id');
        $table->string('first_name');
        $table->string('last_name');
        $table->boolean('azienda');
        $table->string('iva');
        $table->string('ds');
        $table->boolean('fatres');
        $table->string('cf');
        $table->string('mail');
        $table->string('telefono');
        $table->integer('sponsor');
        $table->string('indinst');
        $table->string('civinst');
        $table->string('cityInst');
        $table->string('capinst');
        $table->string('provinst');
        $table->string('indf');
        $table->string('civf');
        $table->string('capf');
        $table->string('provf');
        $table->string('cityFatt');
        $table->timestamps();
    });

How can i complete the migration and create the table? Thank you for answer!

like image 378
Stefano Zaniboni Avatar asked Oct 13 '17 08:10

Stefano Zaniboni


1 Answers

@Stefano Zaniboni answered this in a comment but to expand:

I ran across this issue because I'm used to running php artisan commands in my local directory rather than in a virtualbox / vagrant box / docker container.

The Laravel Docs mention that you need to run the php artisan migrate command from within your virtual machine.

If you're using docker, you can get your container id using docker ps. Then to ssh into the container use docker exec -it <containerId> /bin/bash. Then just cd into your project directory and run php artisan migrate.

like image 146
bill Avatar answered Oct 31 '22 19:10

bill