<p>I am working with janusgraph. I have built a janusgraph image. What I want is to run this janusgraph container, at the same time, connect to cassandra container and elasticsearch container, and finally expose 8182 port to host machine.</p>

<p>My problem is: how to let janusgraph connect to cassandra by ip and 9042 port and elasticsearch by ip and 9200/9300 port?</p>

<p>First, you'll want to <code>EXPOSE</code> those ports in your Dockerfile.  Your Dockerfile is where you'll also want to define an <code>ARG</code> for the Cassandra cluster endpoints.</p>

<p>Dockerfile:</p>

<pre><code># argument for the Cassandra endpoints, with a default value of 127.0.0.1
ARG CASSANDRA_ENDPOINT_LIST=127.0.0.1

# Exposing required ports 8182(gremlin) 9042(Cassandra) 9200(ElasticSearch)
EXPOSE 8182 9042 9200
</code></pre>

<p>Then do a regex/replace with <code>sed</code> in your entrypoint file:</p>

<pre><code>sed -i "s/hostname=127\.0\.0\.1/hostname=${CASSANDRA_ENDPOINT_LIST}/g" ${JANUSGRAPH_CONF}/gremlin-server/janusgraph-cql-es-server.properties
</code></pre>

<p>When building the Docker container, pass <code>CASSANDRA_ENDPOINT_LIST</code> as a build argument:</p>

<pre><code>--build-arg CASSANDRA_ENDPOINT_LIST=1.2.3.4,1.2.3.5
</code></pre>

<p>This example is geared toward Cassandra, but something similar will work for ElasticSearch, too.</p>

<p>Note: You <em>could</em> also build all 3 inside the same container, and then you wouldn't need to pass the endpoints via <code>--build-arg</code>.  Although, you'd need enough RAM to support JVMs for Janus, Elastic, and Cassandra.</p>
