title: Docker Compose Image Failing
body: <p>I am learning about Dockerfiles and docker-compose. When I manually run the Dockerfiles and create the containers they all work as they should however by triggering the build and deploy using a docker-compose.yml script the subscribe container stops working. </p>
  
  <p>The process that works successfully is:</p>
  
  <pre><code>docker build -t cu/broker:1.0.0 broker/
  docker run -d --name broker -p 6379:6379 cu/broker:1.0.0
  docker build -t cu/subscriber:1.0.0 subscriber/
  docker run -d --name subscriber --link broker:db cu/subscriber:1.0.0
  docker build -t cu/publisher:1.0.0 publisher/
  docker run --name publisher --link broker:db -ti cu/publisher:1.0.0
  </code></pre>
  
  <p>After running these commands I have two running containers and an interactive console where I can send individual publish commands to the redis server.</p>
  
  <p>Rather than adding each script to this question together with a folder structure I have written a shell script that resets everything and generates the correct structures and files.</p>
  
  <p>When I trigger the docker-compose.yml script it completes successfully but only the broker container is running, the other two terminate as soon as they start. I don't understand why and even with the --verbose flag I get no useful information to help debug this. This is the command I use to run the script.</p>
  
  <pre><code>docker-compose --verbose up -d
  </code></pre>
  
  <p>And here is the shell script config.sh that builds the folder and file structure.</p>
  
  <pre><code>#!/bin/sh
  # builds the folder structures and dockerfiles
  
  echo "STOPPING RUNNING CONTAINERS"
  docker stop $(docker ps -a -q)
  echo "DELETING ALL CONTAINERS"
  docker rm $(docker ps -a -q)
  echo "DELETING ALL IMAGES"
  docker rmi $(docker images -q)
  docker ps
  docker images
  
  if [ -d docker ]; then
      echo "DELETING EXISTING FILES AND DIRECTORIES"
      rm -rf docker
  fi
  
  echo "CREATING DIRECTORIES AND FILES"
  mkdir docker
  cd docker
  echo -e "broker:" &gt;&gt; docker-compose.yml
  echo -e "  build: broker/" &gt;&gt; docker-compose.yml
  echo -e "  ports:" &gt;&gt; docker-compose.yml
  echo -e "    - \"6379:6379\"\n" &gt;&gt; docker-compose.yml
  echo -e "subscriber:" &gt;&gt; docker-compose.yml
  echo -e "  build: subscriber/" &gt;&gt; docker-compose.yml
  echo -e "  links:" &gt;&gt; docker-compose.yml
  echo -e "    - \"broker:db\"\n" &gt;&gt; docker-compose.yml
  echo -e "publisher:" &gt;&gt; docker-compose.yml
  echo -e "  build: publisher/" &gt;&gt; docker-compose.yml
  echo -e "  links:" &gt;&gt; docker-compose.yml
  echo -e "    - \"broker:db\"\n" &gt;&gt; docker-compose.yml
  
  mkdir broker
  cd broker
  
  echo "CREATING BROKER DOCKERFILE"
  touch Dockerfile
  echo -e "FROM redis:3.0.3" &gt;&gt; Dockerfile
  echo -e  "RUN apt-get update -y &amp;&amp; apt-get upgrade -y\n" &gt;&gt; Dockerfile
  cd ..
  mkdir publisher
  cd publisher
  
  echo "CREATING PUBLISHER DOCKERFILE"
  touch Dockerfile
  echo -e "FROM ubuntu:14.04" &gt;&gt; Dockerfile
  echo -e  "RUN apt-get update -y &amp;&amp; apt-get upgrade -y" &gt;&gt; Dockerfile
  echo -e  "RUN apt-get install -y redis-server &amp;&amp; service redis-server stop" &gt;&gt; Dockerfile
  echo -e  "CMD redis-cli -h $DB_PORT_6379_TCP_ADDR\n" &gt;&gt; Dockerfile
  cd ..
  mkdir subscriber
  cd subscriber
  
  echo "CREATING SUBSCRIBER DOCKERFILE"
  touch Dockerfile
  echo -e "FROM node:0.12.7" &gt;&gt; Dockerfile
  echo -e "RUN apt-get update -y &amp;&amp; apt-get upgrade -y" &gt;&gt; Dockerfile
  echo -e "RUN apt-get install -y apt-utils tree wget nano" &gt;&gt; Dockerfile
  echo -e "WORKDIR /home" &gt;&gt; Dockerfile
  echo -e "ADD index.js /home/index.js" &gt;&gt; Dockerfile
  echo -e "RUN npm install ioredis" &gt;&gt; Dockerfile
  echo -e "CMD ["node", "/home/index.js"]\n" &gt;&gt; Dockerfile
  
  echo "CREATING JAVASCRIPT FILE"
  echo -e "var redis = require('ioredis');" &gt;&gt; index.js
  echo -e "var port = process.env.DB_PORT_6379_TCP_PORT;" &gt;&gt; index.js
  echo -e "var ip = process.env.DB_PORT_6379_TCP_ADDR;\n" &gt;&gt; index.js
  echo -e "client = redis.createClient(port, ip, {});\n" &gt;&gt; index.js
  echo -e "console.log('REDIS PORT: '+port);" &gt;&gt; index.js
  echo -e "console.log('REDIS IP:   '+ip);" &gt;&gt; index.js
  echo -e "console.log('subscribed to "test" channel');\n" &gt;&gt; index.js
  echo -e "client.subscribe('test');\n" &gt;&gt; index.js
  echo -e "client.on('message', function(channel, message) {" &gt;&gt; index.js
  echo -e "    console.log('MESSAGE RECEIVED');" &gt;&gt; index.js
  echo -e "    console.log('CHANNEL: '+channel);" &gt;&gt; index.js
  echo -e "    console.log('MESSAGE: '+message);" &gt;&gt; index.js
  echo -e "});\n" &gt;&gt; index.js
  cd ..
  </code></pre>