title: Unable to connect to Docker container: Connection Refused
body: <p>I have a war file deployed as <code>Docker</code> container on <code>linux ec2</code>. But when I try to hit the <code>http://ec2-elastic-ip:8080/AppName</code>, I don't get any response.</p>
  
  <p>I have all the <code>security group</code> inbound rules set up for both <code>http</code> and <code>https</code>. So that's not a problem.</p>
  
  <p><strong>Debugging</strong></p>
  
  <p>I tried debugging by <code>ssh-ing</code> the linux instance. Tried command <code>curl localhost:8080</code> , this is the response:</p>
  
  <pre><code>curl: (7) Failed to connect to localhost port 8080: Connection refused
  </code></pre>
  
  <p>Tried with <code>127.0.0.1:8080</code> but the same response.</p>
  
  <p>Next thing I did was to list the Docker container: <code>docker ps</code>. I get:</p>
  
  <pre><code>CONTAINER ID  IMAGE  COMMAND  CREATED  STATUS   PORTS   NAMES
  &lt;ID&gt;        &lt;ecr&gt;.amazonaws.com/&lt;my&gt;-registry:2019-05-16.12-17-02   "catalina.sh run"   24 minutes ago      Up 24 minutes       0.0.0.0:32772-&gt;8080/tcp   ecs-app-24-name
  </code></pre>
  
  <p>Now, I connected to this container using <code>docker exec -it &lt;name&gt; /bin/bash</code> and tried checking tomcat logs which clearly shows that my application war is there and tomcat has started.</p>
  
  <p>I ever tried checking the <code>docker-machine ip default</code> but this gave me error:</p>
  
  <pre><code>Docker machine "default" does not exist. Use "docker-machine ls" to list machines. Use "docker-machine create" to add a new one.
  </code></pre>
  
  <p>Now am stuck. Not able to debug further. The result am expecting is to access the app through the url above.</p>
  
  <p>What to do? Is it something am doing wrong?</p>
  
  <p>Also, to mention, the entire infrastructure is managed through <code>terraform</code>. I first create the base image,copy the war to webapps using <code>DockerFile</code>, push the registry image and finally do a <code>terraform apply</code> to apply any changes. </p>