<p>I want to connect two containers with each other ... I start with the creation of an overlay-network <code>mynet</code>:</p>
<pre><code>docker network create -d overlay mynet
</code></pre>
<p>After that, I´ve created the first service <code>activemq</code>:</p>
<pre><code>docker service create --name activemq -p 61616:61616 -p 8161:8161  --replicas 1 --network mynet rmohr/activemq
</code></pre>
<p>This starts and works perfectly fine, I also can access the WebUI http://localhost:8161/admin/</p>
<p>Now I want to start my service <a href="https://hub.docker.com/repository/docker/ni920/timeserviceplain" rel="nofollow noreferrer">TimeService</a> I have the following settings in the container:</p>
<pre><code>docker service create --name timeservice -p 7000:7000  --replicas 1 --network mynet ni920/timeserviceplain:latest
</code></pre>
<pre><code>java.naming.provider.url=tcp://localhost:61616
java.naming.user=admin
java.naming.password=admin
io.jexxa.rest.host=0.0.0.0
io.jexxa.rest.port=7000
</code></pre>
<p>So it should connect via <code>tcp://localhost:61616</code> with the <code>ActiveMQ</code> but it doesn't.</p>
<p>Do you guys have any clue what I should try by the way the communication works perfectly in a none <code>Swarm</code> environment or in a <code>Kubernetes-Pod</code>?</p>

Nico
<p>If you want your containers to communicate witch each other, you can use their names then let network driver resolves their ips.</p>
<p>Here is the <a href="https://docs.docker.com/network/#network-driver-summary" rel="nofollow noreferrer">network driver summary</a> from docker docs:</p>
<blockquote>
<ul>
<li><strong>User-defined bridge networks</strong> are best when you need multiple containers to communicate on the same Docker host.</li>
<li><strong>Host networks</strong> are best when the network stack should not be isolated from the Docker host, but you want other aspects of the container to be isolated.</li>
<li><strong>Overlay networks</strong> are best when you need containers running on different Docker hosts to communicate, or when multiple applications work together using swarm services.</li>
<li><strong>Macvlan networks</strong> are best when you are migrating from a VM setup or need your containers to look like physical hosts on your network, each with a unique MAC address.</li>
<li><strong>Third-party network plugins</strong> allow you to integrate Docker with specialized network stacks.</li>
</ul>
</blockquote>
<hr />
<p>In your case, replace <strong>localhost</strong> with service name <strong>activemq</strong>.</p>
<pre><code>java.naming.provider.url=tcp://activemq:61616
.
.
</code></pre>
