title: Docker API not accessible from within a container
body: <p>I can make cUrl calls to Docker API but if I run the same script from a container (docker-compose), I can't reach any API endpoint.</p>
  <p>My requests looks like :</p>
  <pre><code>$ curl --unix-socket /var/run/docker.sock -X POST http:/localhost/containers/json
  </code></pre>
  <p>The reason could be the use of localhost but I can't find the solution for now. Any suggestions?</p>
  <p>EDIT : Here's a brief summary of the stack i'm using (Api-Platform <a href="https://api-platform.com/" rel="nofollow noreferrer">https://api-platform.com/</a>). Every container is attached to an &quot;api_default&quot; bridge network :</p>
  <ul>
  <li>php = Symfony based application</li>
  <li>nginx = NGINX web server</li>
  <li>psql = Hosts the main database</li>
  <li>mssql = Used to sync datas</li>
  <li>...</li>
  </ul>
  <p>I do have a shell script in my &quot;php&quot; container which is meant to reach the Docker API. To summarize, I request the &quot;mssql&quot; container to sync with an external service and then I ask to &quot;psql&quot; container to copy those datas (export/import done with csv files through shared volumes).</p>
  <p>The problem is :</p>
  <ul>
  <li>If I do <code>docker-compose exec php bin/console app:sync</code> (Symfony command which runs the script), everything works fine : the containers communicate through docker.sock with the Docker API and I can sync my databases.</li>
  <li>But if I run the same script with an api endpoint (localhost:8080/api/sync) or via a VueJS app (Axios), the Docker API never return any response.</li>
  </ul>
  <p>Below is a part of my script :</p>
  <pre><code>curl -XPOST -H 'Content-Type: application/json' \
        --unix-socket /var/run/docker.sock http:/localhost/containers/mssql/exec \
        -d '{
          &quot;AttachStdout&quot;:true,
          &quot;Tty&quot;:true,
          &quot;Cmd&quot;:[&quot;/opt/mssql-tools/bin/sqlcmd&quot;, ...]
        }'
  </code></pre>
  <p>And here is the way I call my Symfony command in the api endpoint Controller :</p>
  <pre><code> /**
    * @Route(&quot;/api/sync&quot;, name=&quot;sync&quot;, methods={&quot;GET&quot;})
    */
    public function sync(KernelInterface $kernel)
    {
      $application = new Application($kernel);
      $application-&gt;setAutoExit(false);
  
      $input = new ArrayInput(array(
          'command' =&gt; 'app:sync'
      ));
  
      $output = new BufferedOutput();
      $application-&gt;run($input, $output);
      $content = $output-&gt;fetch();
  
      return new Response($content);
    }
  </code></pre>
  <p>Maybe should I replace &quot;localhost&quot; with &quot;api_default&quot; to reach the good network, but that doesn't work ... ?</p>