title: Docker compose 3.1, communication between two docker-compose.yml
body: <p>For past 3 days I have been trying to connect two docker containers generated by two separate docker-compose files.</p>
  
  <p>I tried a lot of approaches none seem to be working. Currently after adding  network to compose files, service with added network doesn't start. My goal is to access endpoint from another container. </p>
  
  <p>Endpoint-API compose file:</p>
  
  <pre><code>    version: "3.1"
  
      networks:
        test:
  
      services:
          mariadb:
            image: mariadb:10.1
            container_name: list-rest-api-mariadb
            working_dir: /application
            volumes:
              - .:/application
            environment:
              - MYSQL_ROOT_PASSWORD=root
              - MYSQL_DATABASE=list-api
              - MYSQL_USER=list-api
              - MYSQL_PASSWORD=root
            ports:
              - "8003:3306"
  
          webserver:
            image: nginx:stable
            container_name: list-rest-api-webserver
            working_dir: /application
            volumes:
                - .:/application
                - ./docker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
            ports:
             - "8005:80"
            networks:
             - test
  
          php-fpm:
            build: docker/php-fpm
            container_name: list-rest-api-php-fpm
            working_dir: /application
            volumes:
              - .:/application
              - ./docker/php-fpm/php-ini-overrides.ini:/etc/php/7.2/fpm/conf.d/99-overrides.ini
  </code></pre>
  
  <p>Consumer compose file:</p>
  
  <pre><code>version: "3.1"
  
  networks:
    test:
  
  services:
      consumer-mariadb:
        image: mariadb:10.1
        container_name: consumer-service-mariadb
        working_dir: /consumer
        volumes:
          - .:/consumer
        environment:
          - MYSQL_ROOT_PASSWORD=root
          - MYSQL_DATABASE=consumer
          - MYSQL_USER=consumer
          - MYSQL_PASSWORD=root
        ports:
          - "8006:3306"
  
      consumer-webserver:
        image: nginx:stable
        container_name: consumer-service-webserver
        working_dir: /consumer
        volumes:
            - .:/consumer
            - ./docker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
        ports:
         - "8011:80"
        networks:
         - test
  
      consumer-php-fpm:
        build: docker/php-fpm
        container_name: consumer-service-php-fpm
        working_dir: /consumer
        volumes:
          - .:/consumer
          - ./docker/php-fpm/php-ini-overrides.ini:/etc/php/7.2/fpm/conf.d/99-overrides.ini
  </code></pre>
  
  <p>Could someone tell me best way of accessing API container from within consumer? I'm loosing my mind on this one.</p>