title: Docker tomcat7 container cannot connect to host activemq
body: <p>I am admittedly relatively new to using Docker for environment isolation, but I've run into a problem I am yet to solve, and I'm looking for some advice on how to proceed. Apologies if this is dirt simple.</p>
  
  <p>I have an image built with this Dockerfile:</p>
  
  <pre><code>FROM java:7-jre
  MAINTAINER me &lt;email redacted&gt;
  
  ENV CATALINA_HOME="/usr/local/tomcat" 
  ENV PATH=$CATALINA_HOME/bin:$PATH
  RUN mkdir -p "$CATALINA_HOME"
  
  #Add tomcat tarball with configs 
  #need to figure out if war files should be auto-deploy or manual-deploy via manager
  ADD ./ $CATALINA_HOME
  
  WORKDIR $CATALINA_HOME
  RUN tar -xmvf tomcat.tar.gz --strip-components=1 \
      &amp;&amp; rm bin/*.bat \
      &amp;&amp; rm tomcat.tar.gz*
  
  EXPOSE 8080
  #quite possibly unnecessary to expose 61616
  EXPOSE 61616
  
  CMD catalina.sh run
  </code></pre>
  
  <p>Because my host is Mac OSX, I'm using the boot2docker package.  The port forwarding is a real PITA, but for now I'm just binding host 8080 to container 8080 when I run the container <code>(-p 8080:8080)</code> and I have 8080 forwarded in the boot2docker networking setup.</p>
  
  <p>This image runs a container just fine, and I am able to manually upload and deploy .war files to this container while it's running.</p>
  
  <p>On my local machine, I am running ActiveMQ. Eventually I'll put this in a container but I need to get past this hurdle first.  ActiveMQ is running with the default port 61616 listening, as shown in this netstat output:</p>
  
  <pre><code>14:14 $ netstat -a | grep 6161
  tcp46      0      0  *.61616                *.*                    LISTEN
  </code></pre>
  
  <p>The problem I'm having is that deployed war files in my tomcat container are unable to talk to the physical host on 61616.  Here is the actual error from the catalina.out log on the container (I added some line breaks to make it easier to read):</p>
  
  <pre><code>Could not refresh JMS Connection for destination 'request' - retrying in 5000 ms. 
  Cause: Error while attempting to add new Connection to the pool; nested exception is javax.jms.JMSException: 
  Could not connect to broker URL: tcp://localhost:61616. 
  Reason: java.net.ConnectException: Connection refused
  </code></pre>
  
  <p>Admittedly, I think it's because the war file is configured to use localhost:61616 to connect to AMQ -- it doesn't feel right for localhost inside the container to "work" reaching back to the host.  I'm not sure what variable value I should set that to, or if that's even the actual issue. I would think that if it's a dynamically-allocated black-magic IP address, it'd be relatively painful to keep reconfiguring inside war files.</p>
  
  <p>Corollary: are there other considerations I would need to make beyond this configuration if I wanted to link this tomcat container with an AMQ one? </p>
  
  <p>Thanks in advance for your attention. ~P</p>