title: Running Docker Commands with a bash script inside a container
body: <p>I'm trying to automate deployment with webhooks to the Docker hub based on <a href="https://blog.rainforestqa.com/2015-01-15-docker-in-action-from-deployment-to-delivery-part-3-continuous-delivery/" rel="nofollow">this tutorial</a>. One container runs the web app on port 80. On the same host I run another container that listens for post requests from the docker hub, triggering the host to update the webapp image. The post request triggers a bash script that looks like this:</p>
  
  <pre><code>echo pulling...
  docker pull my_username/image
  docker stop img
  docker rm img
  docker run --name img -d -p 80:80 my_username/image
  </code></pre>
  
  <p>A test payload succesfully triggers the script. However, the container logs the following complaints:</p>
  
  <pre><code>pulling...
  app/deploy.sh: line 4: docker: command not found
  ...
  app/deploy.sh: line 7: docker: command not found
  </code></pre>
  
  <p>It seems that the bash script does not access the host implicitly. How to proceed?</p>
  
  <p>Stuff I tried but did not work:
  when firing up the listener container I added the host IP like this based on the <a href="https://docs.docker.com/reference/commandline/run/" rel="nofollow">docs</a>:</p>
  
  <pre><code>HOSTIP=`ip -4 addr show scope global dev eth0 | grep inet | awk '{print\$2}' | cut -d / -f 1`
  docker run --name listener --add-host=docker:${HOSTIP} -e TOKEN="test654321" -d -p 5000:5000 mjhea0/docker-hook-listener
  </code></pre>
  
  <p>similarly, I substituted the --add-host command with <code>--add-host=dockerhost:$(ip route | awk '/docker0/ { print $NF }')</code> based on <a href="https://github.com/docker/docker/issues/1143#issuecomment-70052272" rel="nofollow">this suggestion</a>.</p>