Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

murilo's avatar
Level 10

Communicate 2 projects with laradock and guzzle

I have been trying to connect .with guzzle on project in other like this -

  $http = new Guzzle;
  return $http->get('http://my-project-api/api/options')->getBody();

but It shows this error -

GuzzleHttp\Exception\ConnectException: cURL error 6: Could not resolve host: my-project-api
I saw this post -

I saw this reference - https://github.com/laradock/laradock/issues/435

that a lot of developers are trying to connect .

I could abstract some things from there , but as I dont have many experience with Docker . I could not understand a lot of things .

In my /etc/hosts ( I am using linux desktop ), I tried to change for -

127.0.0.1  my-project-api
or
172.19.0.1 my-project-api
( I got this IP inspecting the  nginx container  , I found there - "Gateway": "172.19.0.1"  . I can access by postman and in chrome , but not with Guzzle  ) 

or 
172.18.0.1 my-project-api
( I got this IP inspecting  - laradock_backend network , I found there - "Gateway": "172.18.0.1"  .  I can access by postman and in chrome , but not with Guzzle  ) 

all those IPS connect with the api with chrome and with postman , but not with Guzzle . Does have any IP in laradock taht I can access other API with Guzzle ? In that refrence , I could find other methods , but I could not understand . I am using laradock with nginx .

0 likes
2 replies
okusax's avatar

hi @murilo, to be able to connect between two docker containers they need to share a network. Usually, if you run docker-compose all inside that compose project to share a network automatically but if they are two different projects you need to create a network and connect such containers to that network manually.

Try running the following commands replacing shared-network with a name that you like and docker-container-X for your containers:

docker network create shared-network
docker network connect shared-network docker-container-1
docker network connect shared-network docker-container-2

Please or to participate in this conversation.