title: Docker-Compose: How to depends_on a container on another network? I am getting an error saying container 'undefined' even though networks are linked
body: <p>I have 2 different services in 2 distinct docker-compose.yml files in 2 different locations.</p>
  <p><strong>Service 1: wordpress</strong></p>
  <pre><code>version: &quot;3.7&quot;
  
  services:
  
    # Wordpress
    wordpress:
      depends_on:
        - db
      container_name: wordpress
      image: wordpress:latest
      ports:
        - '8000:80'
      restart: unless-stopped
      volumes: ['./:/var/www/html']
      environment:
        WORDPRESS_DB_HOST: db:3306
        WORDPRESS_DB_USER: wordpress
        WORDPRESS_DB_PASSWORD: wordpress
      networks:
        - wpsite
  networks:
    wpsite:
      driver: bridge
  </code></pre>
  <p><strong>Service 2: frontend</strong></p>
  <pre><code>version: &quot;3.7&quot;
  
  services:
    frontend:
      depends_on:
        - wordpress
      container_name: frontend
      restart: unless-stopped
      stdin_open: true
      build:
        context: ../realm-frontend
      volumes:
        - static:/realm-frontend/build
      networks:
        - cms_wpsite
  
  networks:
    cms_wpsite:
      external: true
  
  </code></pre>
  <p>I have a shell script that goes to the 2 locations and runs the docker-compose files to create the containers.</p>
  <p><strong>Script</strong></p>
  <pre><code>cd ~/cms;
  docker-compose -f docker-compose.yml up -d --build --force-recreate
  
  cd ../frontend;
  docker-compose -f docker-compose.yml up -d --build --force-recreate
  </code></pre>
  <p>As you can see I have created the link between the networks using bridge.</p>
  <p>When I <code>docker network inspect {network id}</code> I can see both the containers <code>wordpress</code> and <code>frontend</code> are in the network. However, when the second container is created with the <code>depends_on</code> command, I get the following error.</p>
  <p><code>ERROR: Service 'frontend' depends on service 'wordpress' which is undefined.</code></p>
  <p>I am not sure why this is, given that they're in the same network.</p>
  <p>I'd appreciate any help. Thanks!</p>