title: Cannot connect to remote MSSQL database from stacked docker container
body: <p>I have a problem with connecting to existing remote MSSQL database from inside of a docker container running in stack.</p>
  
  <ol>
  <li>My application consists of three modules (backend, frontend and haproxy)</li>
  <li>Backend module is written in Java (SpringBoot app) and it's also the one that needs to connect do remote MSSQL database (by remote I mean placed on different sever, separate of docker part).</li>
  <li>I have the following docker compose file: </li>
  </ol>
  
  <p><a href="https://i.stack.imgur.com/ndsWb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ndsWb.png" alt="enter image description here"></a></p>
  
  <ol start="4">
  <li><p>I start the stack by using following command:</p>
  
  <pre><code>docker stack deploy -c docker-compose.yml myapp
  </code></pre></li>
  <li><p>The result is, all containers are up and running, but spring app reports that connection to DB is timed out:</p></li>
  </ol>
  
  <p><a href="https://i.stack.imgur.com/PxjoI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PxjoI.png" alt="enter image description here"></a> </p>
  
  <p>Server seems to be configured properly, I am able to access the host from container through telnet.</p>
  
  <p>When running independently (even from docker container) backend app is able to connect to database with no problems, while stacked with docker-compose however it's unable to connect to the very same db.</p>
  
  <p>I've also tried to provide db server IP instead of host name - no success.</p>
  
  <p>Maybe setting up networks section in docker compose would do the trick?</p>