title: Docker container - Connection Establishment
body: <p>I'm new to docker .</p>
  
  <p>I have a instance named Server 1.</p>
  
  <p>I have a java application deployed in Server 1 , which connects mongo db of Server 2, Elastic search of Server 3.</p>
  
  <p>Installed Docker in Server 1.</p>
  
  <p>I wish to deploy the java application via docker in the server 1.
  Written a Dockerfile to deploy the java application in the container, Exposed a port.
  Ran that ,application is running successfully.</p>
  
  <p>Checked that application in <a href="http://Server-1" rel="nofollow noreferrer">http://Server-1</a> IP:exposed-port</p>
  
  <p>But when i try to login , it reports incorrect login.</p>
  
  <p>How to Establish the connection between containers to the Server 2(mongo db ),Server3(Elastic Search )or how to rectify above errors</p>
  
  <p>Tried to assign host's network to the container 
  it reports :</p>
  
  <pre><code>#docker run -d -p 8116:8116 -m 256m myapp1 --net="host"
  421a0c63dd9aea3702eb241721e31c0a0c06357daa555b6155567540896aa014
  /usr/bin/docker-current: Error response from daemon: invalid header field value "oci runtime error: container_linux.go:247: starting container process caused \"exec: \\\"--net=host\\\": executable file not found in $PATH\"\n"
  </code></pre>
  
  <p>but if i ran with out network module initially and tried to assign host's network container,
  it reports:</p>
  
  <pre><code>#docker run -d -p 8116:8116 -m 256m myapp1
  421a0c63dd9aea3702eb241721e31c0a0c06357daa555b6155567540896aa014
  
  #docker run -d -p 8116:8116 -m 256m myapp1 --net="host"
  0bfe71e4c4cab1391735ecb45fa72a025d9c5ff99fddaf42c0b3a252e1eb826c
  /usr/bin/docker-current: Error response from daemon: driver failed programming external connectivity on endpoint evil_goldwasser (03685ca753672a8cd5fab3e6a35d7569536
  46ed9f45e9a927d2ccf1dd532da34): Bind for 0.0.0.0:8116 failed: port is already allocated.
  </code></pre>