title: Calling API in a docker-compose container to another container
body: <p>I'm making an web service using docker-compose environment. But I face to the calling API issue. I'm using nextjs and here is my code.</p>
  <pre class="lang-js prettyprint-override"><code>import { GetServerSideProps } from 'next';
  
  export default function Home() {
    return (
      ...
    );
  }
  
  export const getServerSideProps: GetServerSideProps = async ({ req }) =&gt; {
    fetch('http://localhost:7070/api/users') // &lt;-- error occurred !
      .then((r) =&gt; r.json())
      .then((result) =&gt; console.log('######## shoot in getServerSideProps', result));
  
    return {
      props: {},
    };
  };
  
  </code></pre>
  <p>This is sample code. When I access to this page, the following error comes up</p>
  <pre><code>/app/node_modules/node-fetch/lib/index.js:1461
              reject(new FetchError(`request to ${request.url} failed, reason: ${err.message}`, 'system', err));
                     ^
  FetchError: request to http://localhost:7070/api/users failed, reason: connect ECONNREFUSED 127.0.0.1:7070
  </code></pre>
  <p>How can I call the fetch API?
  My docker setting is following.</p>
  <h2>docker-compose</h2>
  <pre class="lang-yaml prettyprint-override"><code>version: &quot;3&quot;
  services:
    servicebackend:
      container_name: seiwhale-backend
      build:
        dockerfile: Dockerfile.dev
        context: ./services/server
      volumes:
        - /app/node_modules
        - ./services/server:/app
    servicefrontend:
      container_name: seiwhale-frontend
      build:
        dockerfile: Dockerfile.dev
        context: ./services/webapp
      volumes:
        - /app/node_modules
        - ./services/webapp:/app
    serviceredis:
      container_name: seiwhale-redis
      image: &quot;redis&quot;
    nginx:
      container_name: seiwhale-nginx
      restart: always
      build:
        dockerfile: Dockerfile
        context: ./services/nginx
      ports:
        - &quot;7070:80&quot;
  </code></pre>
  <h2>nginx</h2>
  <pre><code>upstream upstreamfrontend {
    server servicefrontend:8080;
  }
  
  upstream upstreambackend {
    server servicebackend:3000;
  }
  
  server {
    listen 80;
  
    location / {
      proxy_pass http://upstreamfrontend;
    }
  
    location /api {
      proxy_pass http://upstreambackend;
    }
  
    location /sockjs-node {
      proxy_pass http://upstreamfrontend;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection &quot;Upgrade&quot;;
    }
  }
  </code></pre>
  <p>Additionally, when the error was occurred, the frontend container is automatically exited like following</p>
  <pre><code>seiwhale-frontend exited with code 1
  </code></pre>
  <p>How can I re-run the frontend container after exit?</p>