How can a container identify which container it is in a set of a scaled docker-compose service?
<p>I have a docker container called <code>node</code> that I want to scale to n containers.
A given <code>node</code> container needs to know which container it is in the set of n scaled <code>node</code> containers.
The total could be in an environment variable, but the current is more troubling.</p>
<pre><code>$ docker-compose scale node=100

Starting projectdir_node_1 ... done
Creating and starting projectdir_node_2 ... done
Creating and starting projectdir_node_3 ... done
Creating and starting projectdir_node_4 ... done
Creating and starting projectdir_node_5 ... done
Creating and starting projectdir_node_6 ... done
Creating and starting projectdir_node_7 ... done
Creating and starting projectdir_node_8 ... done
Creating and starting projectdir_node_9 ... done
...
Creating and starting projectdir_node_99 ... done
Creating and starting projectdir_node_100 ... done
</code></pre>
<p>How can <code>projectdir_node_100</code> know it is node <code>100</code>?
I saw that <code>$HOSTNAME</code> is the container id (e.g. <code>2c73136347cd</code>), but found no ENV variable for the hostname with number I need.</p>
<p>For reference, my <code>docker-compose.yml</code>:</p>
<pre><code>version: '2'
services:
  node:
    build: ./node/
    volumes:
      - ./node/code/:/code:ro
    entrypoint: [&quot;/bin/bash&quot;]
</code></pre>
<p>I found the unsolved <a href="https://stackoverflow.com/questions/36031176/how-to-reach-additional-containers-by-the-hostname-after-docker-compose-scale">How to reach additional containers by the hostname after docker-compose scale?</a>, but I still don't know which container I am.</p>