title: Connect to multiple pre-existing external networks in docker
body: <p>I have two different pre-existing networks created by two separated docker-compose operations. The first one is Kafka and the second one is MySQL DB. The third container is a Kafka consumer, which has to have access to the DB and Kafka topic. So I expect to connect them in another docker-compose something like this so I could use services like &quot;db&quot; or &quot;broker&quot; defined somewhere external:</p>
  <pre><code>version: '2'
  services:
    web:
      build: .
      environment:
        KAFKA_BROKER: broker:29092
        DB_MYSQL_USER: ${DB_MYSQL_REMOTE_USER}
        DB_MYSQL_PASS: ${DB_MYSQL_PASS}
        DB_MYSQL_ADDRESS: db:3306
        KAFKA_TOPIC_NAME: ${KAFKA_TOPIC_NAME}
        KAFKA_GROUP_NAME: ${KAFKA_GROUP_NAME}
  
  networks:
    db_container_default:
      external: true
    kafka_client_default:
      external: true 
  </code></pre>
  <p>Eventually, the container doesn't recognize these networks at all.</p>
  <p>The only way to properly connect to ONLY ONE network is <a href="https://runnable.com/docker/docker-compose-networking" rel="nofollow noreferrer">here</a>.<br />
  So I ended up with settings like this, which is utter lame(connect to the exposed port of the DB by host-ip):</p>
  <pre><code>version: '2'
  services:
    web:
      build: .
      environment:
        KAFKA_BROKER: broker:29092
        DB_MYSQL_USER: ${DB_MYSQL_REMOTE_USER}
        DB_MYSQL_PASS: ${DB_MYSQL_PASS}
        DB_MYSQL_ADDRESS: 192.168.1.103:3307
        KAFKA_TOPIC_NAME: ${KAFKA_TOPIC_NAME}
        KAFKA_GROUP_NAME: ${KAFKA_GROUP_NAME}
  
  networks:
    default:
      external:
        name: kafka_client_default
  </code></pre>
  <p>How should I properly configure my third docker-compose?</p>