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

1

6

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!

Dicast answered 13/10, 2017 at 8:33 Comment(2)
Where are you running this command? (inside docker, outside docker)Cyclonite
Hi! I ran the command outside the docker, but i have solved all the thing executing the bash inside the docker and repeated the command. It worked!Dicast
E
10

@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.

Eboat answered 29/5, 2020 at 22:5 Comment(1)
I was bit by this. In my case I was trying to run a migrate refresh and this is what worked: docker exec -it <CONTAINER ID> php artisan migrate:refreshMullis

© 2022 - 2025 — McMap. All rights reserved.