title: How to run a shell script using dockerfiles CMD
body: <p>I am using dockerfiles to build a simple container. Here is the <code>Dockerfile</code>:</p>
  
  <pre><code>FROM XXXXXXX:5003/base-java
  
  MAINTAINER XXXXX
  
  ADD pubsub/ /opt/pubsub/
  
  CMD ["/opt/pubsub/run.sh"]
  </code></pre>
  
  <p>Content of <code>run.sh</code> is as follows:</p>
  
  <pre><code>#!/bin/bash
  nohup java -jar /opt/pubsub/publish.jar &amp;
  nohup java -jar /opt/pubsub/subscribe.jar &amp;
  </code></pre>
  
  <p>This is simple java application for <code>pub/sub</code>.</p>
  
  <p>Now I have got another container running rabbitmq and I am linking the 2 containers however each of my attempt has just failed and My <code>pub/sub</code> container does not start. Can someone advice how to go about debuggin this issue? Somehow docker logs does not have anything.</p>
  
  <p>Here is how I am linking the containers: <code>sudo docker run -d -P --name pub_sub --link rabbitmq:rabbitmq1 image_pub_sub</code></p>
  
  <p>And here is how I am using the alias name in my <code>pub/sub</code> code </p>
  
  <pre><code>factory = new ConnectionFactory(); 
  factory.setHost("rabbitmq1"); 
  try { connection = factory.newConnection(); 
  channel = connection.createChannel(); 
  channel.queueDeclare("pub", true, false, false, null); 
  } 
  catch (IOException e) { // TODO Auto-generated catch block 
  e.printStackTrace(); }
  </code></pre>
  
  <p>I was expecting that my publish code will create a queue in the rabbitmq container and start pushing messages. My subscriber code will basically connect to the same rabbitmq and start reading the messages.</p>
  
  <p>When I run the command nothing happens it just prints a long id of the new container and exits..When I run <code>sudo docker ps -a</code>, I can see the following: </p>
  
  <pre><code>e8a50d5aefa5     image_pub_sub:latest     "/opt/pubsub/run.sh"     32 minutes ago     Exited (0) 32 minutes ago     pub_sub
  </code></pre>
  
  <p>So this means my container is not running.</p>
  
  <p>Just now I tested by updating the <code>/etc/hosts</code> by launching a new container using the following command: <code>sudo docker run -i -t image_pub_sub /bin/bash</code>. Modified the <code>/etc/hosts</code> of this new container and added the following entry <code>&lt;IP_ADDRESS&gt; rabbitmq1</code> and ran my script <code>/opt/pubsub/run.sh</code> and it appends the nohup file with the following messages:</p>
  
  <pre><code>Message Sent
   [x] Received 'Hello'
  Message Sent
  Message Sent
   [x] Received 'Hello'
  </code></pre>