Home > Net >  php artisan migrate not working in docker and laravel 5
php artisan migrate not working in docker and laravel 5

Time:12-11

I created an Apache container and a MYSQL container.

then, I created a Laravel project with composer.

to type php artisan make:auth, I typed php artisan migrate but, an error occurred.

SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution (SQL: select * from information_schema.tables where table_schema = laravel and table_name = migrations and table_type = 'BASE TABLE')

Exception trace:

1 PDOException::("PDO::__construct(): php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution") /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70

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

I checked .env file and /config/database.php. Below is .env file and /config/database.php.

DB_CONNECTION=mysql
DB_HOST=otameshi_db
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=laravel
DB_PASSWORD=ss119
        'mysql' => [
            'driver' => 'mysql',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST', 'otameshi_db'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'laravel'),
            'username' => env('DB_USERNAME', 'laravel'),
            'password' => env('DB_PASSWORD', 'ss119'),
            'unix_socket' => env('DB_SOCKET', ''),
version: '3'
services:
  backend:
    build:
      context: ./docker/php
      dockerfile: Dockerfile
    ports:
      - "80:80"
    volumes:
      - ./src/backend:/var/www/html
    depends_on:
      - db

  db:
    build:
      context: ./docker/mysql
      dockerfile: Dockerfile
    command: --default-authentication-plugin=mysql_native_password
    ports:
      - "3306:3306"
    volumes:
      - ./docker/mysql/data:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=pass

and Below is the outcome of show databases.

enter image description here

.
├── docker
│   ├── mysql
│   │   ├── Dockerfile
│   │   ├── my.cnf
│   │   └── data
│   └── php
│       ├── 000-default.conf
│       └── Dockerfile
├── docker-compose.yml
└── src
    ├── backend
    └── frontend

Where is the mistake in my setting? Thank you for your help.

CodePudding user response:

I had same error and I solved it with DB_HOST=localhost or 127.0.0.1, or you can try to name it DB_HOST=db as it is in Dockerfile.

  • Related