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

murilo's avatar
Level 10

connect Laravel apps locally with Docker via Console

Hello , I have been using this method of Andrew Schmelyun

https://www.youtube.com/watch?v=LFrBmvgamGI

to connectone laravel project to other with docker .

this is the code -

    $client = new Client;
        $request = $client->get('http://laravel_server:80/api/test-connection"');
        $response = $request->getBody()->getContents();

well , it is working . if I access via browser ( via http ) But if ,I run in console instead brouser . it gives error

via console , the same code does not work . I did a command -

docker-compose run  --rm artisan create:my-comand

and gives this error -

   GuzzleHttp\Exception\ConnectException 

  cURL error 6: Could not resolve host: elk_server (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for http://laravel_server/api/test-connection

  at vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:210
    206▕         }
    207▕ 
    208▕         // Create a connection exception if it was a specific error code.
    209▕         $error = isset($connectionErrors[$easy->errno])
  ➜ 210▕             ? new ConnectException($message, $easy->request, null, $ctx)
    211▕             : new RequestException($message, $easy->request, $easy->response, null, $ctx);
    212▕ 
    213▕         return P\Create::rejectionFor($error);
    214▕     }

      +14 vendor frames 
  15  app/Console/Commands/CreateStatisticPropertyActions.php:42
      GuzzleHttp\Client::get("http://laravel_server:80/api/test-connection")

      +13 vendor frames 
  29  artisan:37
   

I tryed as well withh HTTP clas -

 Http::get("laravel_server:80/api/test-connection");

the same error happens

0 likes
4 replies
galilio's avatar

Docker isn't the issue here. You don't know how to deploy a laravel application. If you can't do that, you won't be able to do the steps necessary to create a production ready image https://mobdro.bio/ .

murilo's avatar
Level 10

it is not to deploy . it is to work local

murilo's avatar
Level 10

I think that is something that could be changed at the kernel - this is the kernel of api , this works

'api' => [
            // \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
            'throttle:api',
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
        ],

``

does the  console. uses some kernel ?
murilo's avatar
Level 10

I tryed to connect as well with the IP , inside the command . it gives this error -

cURL error 28: Connection timeout after 10001 ms (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for http://192.168.96.3/api/test-connection

inside the controller , it works . I realy dont understand . I I acces the api it works , but if I give a command . does not work the access

Please or to participate in this conversation.