neoighodaro / laravel-docker

Getting Started With Laravel and Docker.
55 stars 27 forks source link

SQLSTATE[HY000] [2002] php_network_getaddresses when migrate #4

Open franmadj opened 5 years ago

franmadj commented 5 years ago

when php artisan migrate I get:

Illuminate\Database\QueryException : SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name does not resolve (SQL: select * from information_schema.tables where table_schema = homestead and table_name = migrations)

using mysql this is my .env:

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

and this the docker-compose.yml:

version: '3'
services:
  webapp:
    env_file: .env
    restart: unless-stopped
    build:
      context: ./web
      args:
        - PHP_VERSION=${PHP_VERSION}
        - COMPOSER_HASH=${COMPOSER_HASH}
        - ALPINE_VERSION=${ALPINE_VERSION}
        - NGINX_HTTP_PORT=${NGINX_HTTP_PORT}
        - NGINX_HTTPS_PORT=${NGINX_HTTPS_PORT}
    ports:
      - '8888:80'
    volumes:
      - ./web/src:/var/www
      - ./logs/web:/var/www/storage/logs
    links:
      - mysql
    depends_on:
      - mysql
  mysql:
    env_file: .env
    restart: unless-stopped
    build: ./databases/mysql
    volumes:
      - ./logs/mysql:/var/log/mysql
      - ./storage/mysql:/var/lib/mysql
      - ./databases/mysql/conf.d:/etc/mysql/conf.d

Thanks.

neoighodaro commented 5 years ago

Where did you run the migrate command? In the container or outside it


From: Francisco Mauri notifications@github.com Sent: Sunday, December 30, 2018 6:07 PM To: neoighodaro/laravel-docker Cc: Subscribed Subject: [neoighodaro/laravel-docker] SQLSTATE[HY000] [2002] php_network_getaddresses when migrate (#4)

when php artisan migrate I get:

Illuminate\Database\QueryException : SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name does not resolve (SQL: select * from information_schema.tables where table_schema = homestead and table_name = migrations)

using mysql this is my .env:

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

and this the docker-compose.yml:

version: '3' services: webapp: env_file: .env restart: unless-stopped build: context: ./web args:

Thanks.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/neoighodaro/laravel-docker/issues/4, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AAxRlvyA6AnnLWcyxrIxyvrojoG1dqsHks5u-PLXgaJpZM4ZlAUK.

franmadj commented 5 years ago

Inside the app container, outside the container there is not DB, I believe containers communicate each other through its default internal network(unless you create a custom one) and uses the service's name as interface instead the localhost or ip.

yehia67 commented 4 years ago

I have the same problem

0xMH commented 3 years ago

Anyone reached a solution for this problem? I'm facing the same Behavior.