Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"php_network_getaddresses: getaddrinfo failed: Name or service not known[xxxx] #2503

Closed
pizsd opened this issue Feb 12, 2020 · 13 comments
Closed

Comments

@pizsd
Copy link

pizsd commented Feb 12, 2020

Description:

mysql, redis This problem occurs under the debug of phpstorm. This problem does not occur directly in the browser or postman. I want to know what causes it.

error

redis
php_network_getaddresses: getaddrinfo failed: Name or service not known [tcp://reids:6379]
mysql
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known

Project configuration file .env
redis

REDIS_HOST=reids
REDIS_PASSWORD=null
REDIS_PORT=6379

mysql

DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=campaign
DB_USERNAME=root
DB_PASSWORD=root

docker fo mac
dcoker:19.03
docker-compsoe:1.25.2

@bestlong
Copy link
Member

bestlong commented Feb 18, 2020

check container working first.
docker-compse ps
docker-compse logs mysql
docker-compse logs redis

Ref #2507

@metalcamp
Copy link
Contributor

Probably typo:

REDIS_HOST=reids

@pizsd
Copy link
Author

pizsd commented Feb 21, 2020

@metalcamp Not the problem, the configuration is wrong

@metalcamp
Copy link
Contributor

@pizsd: Is your redis service (in docker-compose.yml) also named reids?

@bestlong
Copy link
Member

bestlong commented Mar 2, 2020

edit .env file

REDIS_HOST=redis

@ugurdnlr
Copy link

ugurdnlr commented Apr 21, 2020

I'm getting this error too.

Illuminate\Database\QueryException : SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known

when i run tests from phpstorm I'm getting this. But i didn't get this when i run from terminal like phpunit Tests\ExampleTest

My project .env

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

laradock .env

MYSQL_VERSION=5.7
MYSQL_DATABASE=default
MYSQL_USER=default
MYSQL_PASSWORD=secret
MYSQL_PORT=3306

docker-compose.yml

mysql:
      build:
        context: ./mysql
        args:
          - MYSQL_VERSION=${MYSQL_VERSION}
      environment:
        - MYSQL_DATABASE=${MYSQL_DATABASE}
        - MYSQL_USER=${MYSQL_USER}
        - MYSQL_PASSWORD=${MYSQL_PASSWORD}
        - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
        - TZ=${WORKSPACE_TIMEZONE}
      volumes:
        - ${DATA_PATH_HOST}/mysql:/var/lib/mysql
        - ${MYSQL_ENTRYPOINT_INITDB}:/docker-entrypoint-initdb.d
      ports:
        - "${MYSQL_PORT}:3306"
      networks:
        - backend

@ugurdnlr
Copy link

My Solution:

PhpStorm->Preferences->Languages & Frameworks->PHP->Test Frameworks

Add PHPUnit by Remote Interpreter

Select Docker interpreter

After created you should add link ( Links section ) which one do u want to use ( mysql, redis) to docker container (click Browse in docker container section)

And if you know which network is using in docker container you should write name of network ( docker network ls ) into Network Mode section then click OK . That’s it.

But if you don’t know which network is using . First you should remove all unused networks ( docker network prune ) then run ( docker network ls )

@stale
Copy link

stale bot commented Jul 21, 2020

Hi 👋 this issue has been automatically marked as stale 📌 because it has not had recent activity 😴. It will be closed if no further activity occurs. Thank you for your contributions ❤️.

@stale stale bot added the Stale label Jul 21, 2020
@stale
Copy link

stale bot commented Aug 11, 2020

Hi again 👋 we would like to inform you that this issue has been automatically closed 🔒 because it had not recent activity during the stale period. We really really appreciate your contributions, and looking forward for more in the future 🎈.

@stale stale bot closed this as completed Aug 11, 2020
@maMykola
Copy link

My Solution:

PhpStorm->Preferences->Languages & Frameworks->PHP->Test Frameworks

Add PHPUnit by Remote Interpreter

Select Docker interpreter

After created you should add link ( Links section ) which one do u want to use ( mysql, redis) to docker container (click Browse in docker container section)

And if you know which network is using in docker container you should write name of network ( docker network ls ) into Network Mode section then click OK . That’s it.

But if you don’t know which network is using . First you should remove all unused networks ( docker network prune ) then run ( docker network ls )

changing Network mode from bridge to docker internal network fixed my problem

@BonBonSlick
Copy link

BonBonSlick commented Sep 17, 2021

In my case error was misleading. You have to run commands from docker container eg docker-compose exec containerName (app) php (serviceName) bin/console doctrine:migrations:migrate (service command).
I was trying to run it from outside of the container. Dunno how not connected redis to doctrine is related during doctrine command, but that was the case. Lost 2-3 hours on that and asked for help other dev.

@HuyNguyen206
Copy link

hi @ugurdnlr,
Regarding this section "After created you should add link ( Links section ) which one do u want to use ( mysql, redis) to docker container (click Browse in docker container section)", could you explain in more detail with screenshot?
I try to config but an error occurs
This is screenshots of my config
image
image
image

Thanks in advance

@keizah7
Copy link

keizah7 commented Apr 11, 2023

My Solution:

PhpStorm->Preferences->Languages & Frameworks->PHP->Test Frameworks

Add PHPUnit by Remote Interpreter

Select Docker interpreter

After created you should add link ( Links section ) which one do u want to use ( mysql, redis) to docker container (click Browse in docker container section)

And if you know which network is using in docker container you should write name of network ( docker network ls ) into Network Mode section then click OK . That’s it.

But if you don’t know which network is using . First you should remove all unused networks ( docker network prune ) then run ( docker network ls )

thank you! Changed Network mode to my subnet in Docker container settings and it started working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants