Accessing Docker-compose containers hostnames from a container
<p>I'm trying to setup an app that works as a Peer Sampling Service. Each peer would run on a separate container and for ease of use I'd have one tracker that would give to each peer its initial view.</p>

<p>For the tracker I'm running it as a Python 3.5 web server that has a simple REST API. when contacted it calls <code>docker-compose -H tcp://hostip:2375 ps</code> to get the list of containers and their hostnames.</p>

<p>Strangely though when this container executes this command, the docker daemon answers with an empty list, whereas if I ask this daemon not from the container but from my computer or even from an other computer on the same local network it works fine.</p>

<p>I have no idea why the daemon would send two different results.</p>

<p>Here is my Dockerfile</p>

<pre><code>FROM python:3.5.1

# RUN pip install pydevd

ADD . /code
WORKDIR /code

EXPOSE 4321

RUN echo 'starting Tracker'
CMD [ "python", "./scripts/tracker.py" ]
</code></pre>

<p>my docker-compose.yml</p>

<pre><code>version: '2'
services:
  pss:
    build: .
  tracker:
    expose:
      - "4321"
    build:
      context: .
      dockerfile: Dockerfile-tracker
</code></pre>

<p>and the line in the python file :
<code>ps_output = subprocess.check_output('docker-compose -H tcp://&lt;daemon_host_ip&gt;:2375 ps', shell=True).decode().splitlines()</code></p>