1

I use laradock for a few days. I had it working but since today run into a problem when running "php artisan migrate" error code:

"Illuminate\Database\QueryException SQLSTATE[HY000] [2002] 
php_network_getaddresses: getaddrinfo failed: 
Name or service not known 
(SQL: SHOW FULL TABLES WHERE table_type = 'BASE TABLE')"

My containers are all up and running and I can access my workspace and my mysql container and see the (previously created) tables in my mysql container. My .env file shows:


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

most notably my DB_HOST name is mysql which seems to be the problem in most threads I found about the topic.

My docker containers show:

$ docker-compose ps
        Name                   Command           State            Ports        
-------------------------------------------------------------------------------
f3acb119d329_laradock   docker-entrypoint.sh    Up         0.0.0.0:3307->3306/t
_mysql_1                mysqld                             cp, 33060/tcp       
laradock_docker-in-     dockerd-entrypoint.sh   Up         2375/tcp, 2376/tcp  
docker_1                                                                       
laradock_nginx_1        /bin/bash               Up         0.0.0.0:443->443/tcp
                        /opt/startup.sh                    , 0.0.0.0:8881->80/t
                                                           cp,                 
                                                           0.0.0.0:81->81/tcp  
laradock_php-fpm_1      docker-php-entrypoint   Up         9000/tcp            
                        php-fpm                                                
laradock_phpmyadmin_1   /docker-entrypoint.sh   Exit 128                       
                        apac ...                                               
laradock_redis_1        docker-entrypoint.sh    Up         0.0.0.0:6379->6379/t
                        redis ...                          cp                  
laradock_workspace_1    /sbin/my_init           Up         0.0.0.0:2222->22/tcp
                                                           , 0.0.0.0:3000->3000
                                                           /tcp, 0.0.0.0:3001->
                                                           3001/tcp, 0.0.0.0:80
                                                           01->8000/tcp, 0.0.0.
                                                           0:8080->8080/tcp    

It would be great if someone could help me with this, because I unsuccessfully tried to fix it all day. If more information is required please tell me what's missing to solve this.

  • Possible duplicate of - https://stackoverflow.com/questions/30182984/sqlstatehy000-2002-php-network-getaddresses-getaddrinfo-failed-name-or-ser – sn n May 05 '20 at 15:43

1 Answers1

1

Connection failed: SQLSTATE[HY000] [2002] Connection refused.

please use docker internal IP as host and try to connect MySQL.

Use docker inspect command to get IP info.

jithu thomas
  • 279
  • 1
  • 3
  • Thank you. Changing the host to the docker container helped. My migrations now work again. I changed following line in my projects .env file: DB_HOST=f3acb119d329_laradock_mysql_1 The db host is now my docker container of my mysql container. However, I'm wondering whether this name will change and therefore I'll have to refix the issue every time my container name changes. Would the IP be more stable? – Max Peuntinger May 08 '20 at 07:19