title: Docker how to send request(curl - get, post) one container to another container
body: <p>GET(and POST PUT ....) request using curl in one container to another.</p>
  
  <p><strong>$ docker ps</strong></p>
  
  <pre><code>CONTAINER ID    IMAGE      COMMAND       PORTS                                           NAMES
  b184219cd8f6    otp_totp  "./run.sh"    0.0.0.0:3000-&gt;3000/tcp                           totp_api
  c381c276593f    service   "/bin/sh -c"  0.0.0.0:8000-&gt;8000/tcp, 0.0.0.0:9000-&gt;9000/tcp   service
  d0add6b1c72e    mysql     "/tmp/run.sh" 0.0.0.0:3306-&gt;3306/tcp                           mysql
  </code></pre>
  
  <p>when I send request <code>curl -X GET http://localhost.3000</code> to <code>totp_api container</code> in local</p>
  
  <p><code>totp_api</code> return <code>{'status':200}</code> </p>
  
  <p>but I want send request in <code>service</code> container</p>
  
  <p>like// <code>curl -X GET http://localhost:3000</code> to <code>totp_api</code> container in <code>service</code>(docker exec -it /bin/bash), <code>totp_api</code> will return <code>{'status':200}</code> to <code>server</code> container</p>
  
  <pre><code>project_folder
               ㄴ- docker-compose.yml # service, mysql container
  api_folder
           ㄴ- docker-compose.yml # totp_api container
  </code></pre>
  
  <p>please some body tell me some advice</p>
  
  <hr>
  
  <h2>after</h2>
  
  <p><strong>api/folder/docker-compose.yml</strong></p>
  
  <pre><code>version: '3'
  services:
      totp:
          build: .
          container_name: totp_api
          volumes:
              - $PWD:/home
          ports:
              - "3000:3000"
          tty: true
          restart: always
          networks:
              - bridge
  
  networks:
      bridge:
          driver: bridge
  </code></pre>
  
  <p>-</p>
  
  <pre><code>$ docker-compose up -d
  $ docker network ls
  
  NETWORK ID          NAME                DRIVER              SCOPE
  4a05be5e600f        bridge              bridge              local
  503d0586c7ec        host                host                local
  ########            ####
  727bfc6cc21f        otp_bridge          bridge              local
  ########            ####
  3c19d98d9ca5        otp_default         bridge              local
  </code></pre>
  
  <p>-</p>
  
  <pre><code>$ docker network inspect otp_bridge
  
  [
      {
          "Name": "otp_bridge",
          "Id": "727bfc6cc21fd74f19eb7fe164582637cbad4c2d7e36620c1c0a1c51c0490d31",
          "Created": "2017-12-13T06:12:40.5070258Z",
          "Scope": "local",
          "Driver": "bridge",
          "EnableIPv6": false,
          "IPAM": {
                  "Driver": "default",
                  "Options": null,
                  "Config": [
                      {
                          "Subnet": "172.19.0.0/16",
                          "Gateway": "172.19.0.1"
                      }
                  ]
              },
              "Internal": false,
              "Attachable": true,
              "Ingress": false,
              "ConfigFrom": {
                  "Network": ""
              },
              "ConfigOnly": false,
              "Containers": {
          "02fa407062cdd5f6f368f2d17c5e68d2f9155d1d9b30c9edcbb2386a9ded648a": {
                  "Name": "totp_api",
                  "EndpointID": "860c47da1e70d304399b42917b927a8cc6717b86c6d1ee6f065229e33f496c2f",
                  "MacAddress": "02:42:ac:13:00:02",
                  "IPv4Address": "172.19.0.2/16",
                  "IPv6Address": ""
              }
          },
          "Options": {},
          "Labels": {
              "com.docker.compose.network": "bridge",
              "com.docker.compose.project": "otp"
          }
      }
  ]
  </code></pre>