Creating a network on docker swarm between docker-compose applications and other containers
<p>So, let's say I have an application that gets deployed to Docker Swarm and it has a compose file that looks something like:</p>

<pre><code>version: '2'

services:
  postgres:
    image: postgres
    environment: 
      - POSTGRES_PASSWORD=password
    networks:
      - app-network
    volumes: 
      - postgres:/var/lib/postgresql/data

  myapp:
    container_name: 'myapp'
    image: myapp:debug
    depends_on:
      - postgres
    build:
      context: .
      dockerfile: Dockerfile.debug
    networks:
      - app-network

networks:
  app-network:
    driver: bridge

volumes:
  postgres:
</code></pre>

<p>Maybe I want to have several of these applications deployed and they communicate via a rabbitmq container. I thought I could just create a network on the swarm like so:</p>

<pre><code>$ docker network create -d overlay common-network
</code></pre>

<p>And then I could provision a rabbitmq instance like so:</p>

<pre><code>$ docker run -d \
--hostname rabbit \
--name rabbit \
-e RABBITMQ_ERLANG_COOKIE='bleh' \
-e RABBITMQ_DEFAULT_USER='rabbitmq' \
-e RABBITMQ_DEFAULT_PASS='rabbitmq' \
-e RABBITMQ_DEFAULT_VHOST='/' \
rabbitmq:3
</code></pre>

<p>Then deploy my applications:</p>

<pre><code>$ docker-compose up
</code></pre>

<p>But, it doesn't look like the applications can reach "rabbit". </p>

<pre><code>$ docker network ls
NETWORK ID          NAME                                                 DRIVER              SCOPE
176e455e8215        common                                               overlay             global
8f1b14690f2b        swarm-agent-40001BF7000000/bridge                    bridge              local
3cfaae53a0dc        swarm-agent-40001BF7000000/host                      host                local
a01b27b94fcc        swarm-agent-40001BF7000000/none                      null                local
aa6f5b56a6d3        swarm-agent-40001BF7000000/publish_app-network   bridge              local
</code></pre>

<p>The applications can see services that are defined in the same compose file (as shown above), but they can't see services outside of that.</p>

<p>How can I get all the applications on the same network?</p>

<p><strong>EDIT 1</strong>
I have also tried changing the compose file to this:</p>

<pre><code>networks:
      - app-network
      - common

networks:
  adapter-network:
    driver: bridge
  common:
    external: true
</code></pre>