title: Make sure a request is coming from another container in the network in docker-compose
body: <p>Sometimes simple task seems to be more complex. It's what I am facing right now.</p>
  
  <p>I am developing an e-commerce API. The app has a microservice based architecture. So, <code>Order</code>, <code>Product</code>, <code>Payment</code> and <code>Auth</code> these are different microservices. Each has it's own database.</p>
  
  <p>These microservices communicate each other over <code>http restful apis</code>. So If a user places an order it talk to payment microservice to get generated checksum so that he can make payment. Payment microservice talks to <code>Order</code> to place an order.</p>
  
  <p>Order microservice places an order and returns details to payment. No problem.</p>
  
  <p>But after placing order, Product quantity must be reduced. I don't have any API to reduce product quantity. I don't want to have one.</p>
  
  <p>Because, a product is only can be modified by its supplier. Supplier, indeed, can alter his product, but for this he passes his <code>jwt</code>.</p>
  
  <p>If I make an API to alter product quantity, anyone can hit the api and reduce the quantity.</p>
  
  <p>So, one solution can be an API that is only accessible by microservices.</p>
  
  <p>How can I know that the call is coming from a microservice?</p>
  
  <p>Should I create some <code>hash</code> and pass it while interacting with other microservice?</p>
  
  <p>Docker-compose.yml</p>
  
  <pre><code>
      version: '3'
  services:
    users:
      build: './users'
      ports:
        - '4001:3000'
      volumes:
        - './users:/src/'
    products:
      build: './products'
      ports:
        - '4002:3000'
      volumes:
        - './products:/src/'
    orders:
      build: './orders'
      ports:
        - '4003:3000'
      volumes:
        - './orders:/src/'
    payments:
      build: './payments'
      ports: 
        - '4004:3000'
      volumes: 
        - './payments:/src/'
  
  </code></pre>
  
  <p>Dockerfile</p>
  
  <pre><code>#User node js official image as a parent image
  FROM node
  
  ADD package.json /tmp/package.json
  
  RUN cd /tmp &amp;&amp; npm install
  
  RUN mkdir -p /src &amp;&amp; cp -a /tmp/node_modules /src/
  
  COPY . /src
  
  WORKDIR /src
  
  RUN npm install
  
  EXPOSE 3000
  
  CMD npm start
  </code></pre>