title: Connecting dockerized apps network to do api call
body: <p>I have a bit of a problem with connecting the dots.</p>
  
  <p>I managed to dockerized our legacy app and our newer app, but now I need to make them to <code>talk</code> to one another via API call.</p>
  
  <p>Projects:</p>
  
  <ul>
  <li>Project1 = using <code>project1_appnet</code> (bridge driver)</li>
  <li>Project2 = using <code>project2_appnet</code> (bridge driver)</li>
  <li>Project3 = using <code>project3_appnet</code> (bridge driver)</li>
  </ul>
  
  <p>On my local, I have these 3 projects on 3 separates folders. Each project will have their own <code>app</code>, <code>db</code> and <code>cache</code> services.</p>
  
  <p>This is the <code>docker-compose.yml</code> for one of the project. (They have nearly all the same docker-compose.yml only with different image and volume path)</p>
  
  <pre><code>version: '3'
  services:
    app:
      build: ./docker/app
      image: 'cms/app:latest'
      networks:
        - appnet
      volumes:
        - './:/var/www/html:cached'
      ports:
        - '${APP_PORT}:80'
      working_dir: /var/www/html
    cache:
      image: 'redis:alpine'
      networks:
        - appnet
      volumes:
        - 'cachedata:/data'
    db:
      image: 'mysql:5.7'
      environment:
        MYSQL_ROOT_PASSWORD: '${DB_ROOT_PASSWORD}'
        MYSQL_DATABASE: '${DB_DATABASE}'
        MYSQL_USER: '${DB_USER}'
        MYSQL_PASSWORD: '${DB_PASSWORD}'
      ports:
        - '${DB_PORT}:3306'
      networks:
        - appnet
      volumes:
        - 'dbdata:/var/lib/mysql'
  networks:
    appnet:
      driver: bridge
  volumes:
    dbdata:
      driver: local
    cachedata:
      driver: local
  
  </code></pre>
  
  <p>Question:</p>
  
  <ul>
  <li>How can I make them be able to talk to one another via API call? (On my local for development and for prod environment)</li>
  <li>On production, the setting will be a bit different, they will be in different machines but still in the same VPC or even through public network. What is the setting for that?</li>
  </ul>
  
  <p>Note:</p>
  
  <ul>
  <li>I have been looking at <code>link</code> but apparently it is deprecated for <code>v3</code> or not really recommended</li>
  <li>Tried <code>curl</code> from project1 container to project2 container, by doing:</li>
  </ul>
  
  <pre><code>root@bc3afb31a5f1:/var/www/html# curl localhost:8050/login
  curl: (7) Failed to connect to localhost port 8050: Connection refused
  </code></pre>