title: How to restart a docker service using Shell Script
body: <ul>
  <li>I have <code>Node</code> service which is running in Docker container
  
  <ul>
  <li>Due following exception service gets stopped after some time.</li>
  </ul></li>
  </ul>
  
  <p><code>events.js:141 throw er; // Unhandled 'error' event
  Error: read ECONNRESET
          at exports._errnoException (util.js:870:11)
          at TLSWrap.onread (net.js:544:26)</code></p>
  
  <ul>
  <li>I am not aware why this exception is coming up.</li>
  <li>I am looking for work around which can restart the service once its stop.</li>
  <li>I am using <code>shell</code> file to run these service, So is there something that I can add in shell file which can restart this stopped service.</li>
  </ul>
  
  <p>Here is a sample of my shell file:</p>
  
  <pre><code>#!/bin/bash
  ORGANISATION="$1"
  SERVICE_NAME="$2"
  VERSION="$3"
  ENVIRONMENT="$4"
  INTERNAL_PORT_NUMBER="$5"
  EXTERNAL_PORT_NUMBER="$6"
  NETWORK="$7"
  docker build -t ${ORGANISATION}/${SERVICE_NAME}:${VERSION} --build-arg PORT=${INTERNAL_PORT_NUMBER} --build-arg ENVIRONMENT=${ENVIRONMENT} --no-cache .
  docker stop ${SERVICE_NAME}
  docker rm ${SERVICE_NAME}
  
  sudo npm install
  sudo npm install -g express
  docker run -p ${EXTERNAL_PORT_NUMBER}:${INTERNAL_PORT_NUMBER} --network ${NETWORK} --restart always --name ${SERVICE_NAME} -itd ${ORGANISATION}/${SERVICE_NAME}:${VERSION}
  </code></pre>
  
  <p>Here is my Dockerfile</p>
  
  <pre><code>FROM ubuntu
  
  ARG ENVIRONMENT
  ARG PORT
  
  ENV PORT $PORT
  ENV ENVIRONMENT $ENVIRONMENT
  
  RUN apt-get update -qq
  RUN apt-get install -y build-essential nodejs npm nodejs-legacy vim
  
  RUN mkdir /database_service
  ADD . /database_service
  WORKDIR /database_service
  
  RUN npm install -g path
  RUN npm cache clean
  
  EXPOSE $PORT
  
  ENTRYPOINT [ "node",  "server.js" ]
  CMD [ $PORT, $ENVIRONMENT ]
  </code></pre>
  
  <p>Thanks in advance.</p>