First of all, please forgive me if any information is missing or if my question does not meet the standards required by the site. I have very basic knowledge of docker, linux and networking and I am lost.

I use Ubuntu version 20.2 and I have docker version 20.10.10.

I have a system (CakePHP) running in a docker container, and an API (LARAVEL) running on my machine's local host (outside of the docker container), and I need to consume that API on the system from inside the docker container.

This is the content of docker-compose.yml

version: '2'
      context: .
      dockerfile: Dockerfile
    image: php-c10-56
      - /srv/:/srv/
      - /var/www/html/:/var/www/html/
      - "9056:80"
      - "9443:443"
      - net30
    container_name: "docker-php56"
    driver: "bridge"
      driver: default
        - subnet:

As I understand it, the system (CakePHP) is running inside this subnet. And the system (CakePHP) to connect to PostgreSQL, connects through IP (I think it's the gateway to access the local host of my machine).

The API I can consume normally by Postman. Here is a screenshot of a test. inserir a descrição da imagem aqui

And on the system (CakePHP) from inside the docker container, I'm trying to consume like this (just testing for now). inserir a descrição da imagem aqui

It takes a while trying to connect, but without success. This is the return obtained ( sorry for the array format).

    [response] => 
    [info] => Array
            [url] =>
            [content_type] => 
            [http_code] => 0
            [header_size] => 0
            [request_size] => 0
            [filetime] => -1
            [ssl_verify_result] => 0
            [redirect_count] => 0
            [total_time] => 130.124754
            [namelookup_time] => 1.8E-5
            [connect_time] => 0
            [pretransfer_time] => 0
            [size_upload] => 0
            [size_download] => 0
            [speed_download] => 0
            [speed_upload] => 0
            [download_content_length] => -1
            [upload_content_length] => -1
            [starttransfer_time] => 0
            [redirect_time] => 0
            [redirect_url] => 
            [primary_ip] =>
            [certinfo] => Array

            [primary_port] => 8000
            [local_ip] => 
            [local_port] => 0

Here is the method used to consume the API (in case that information is important).

private function callAPI($options){

        $ch = curl_init();

        $header = array(
            "Content-Type: application/json",
            "Authentication: bearer {$integrador['token']}"

        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_HEADER, FALSE);

        if(!empty($data) OR $verb == 'POST'){
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
            curl_setopt($ch, CURLOPT_POST, TRUE);    

            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $verb);

        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);

        $response = curl_exec($ch);
        $info = curl_getinfo($ch);

        return array('response' => $response, 'info' => $info);

1 Answer 1


I'm not sure I can help you, but this might :


tldr (bridge mode):

to get the ip of the container (in container CLI) : ip addr show eth0

to get the ip of the host's docker interface (host CLI) : sudo ip addr show docker0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.