title: Connecting to mysql running inside a docker container using localhost and a port number
body: <p>I have situation where i have MySQL and tomcat running inside two separate containers , and i am deploying a war containing a hibernate.cfg.xml with following connection URL 
  <code>&lt;property name="hibernate.connection.url"&gt;jdbc:mysql://localhost:3306/development_Blobs_001&lt;/property&gt;</code>  </p>
  
  <p>i have docker-compose.yml which looks like this </p>
  
  <pre><code>services:
  
      database:
          build : database
          restart : always
          ports : 
             - "3306:3306"  #HOST_PORT:CONTAINER_PORT
          environment :
              MYSQL_USER : root
              MYSQL_ROOT_PASSWORD : password
  
      webapp:
          build : server
          ports : 
            - "8080:8080"
          links :
            - database
  </code></pre>
  
  <p>now the problem is <strong>i am able to connect</strong> to the database if i use following connection URL </p>
  
  <p><code>&lt;property name="hibernate.connection.url"&gt;jdbc:mysql://database:3306/development_Blobs_001&lt;/property&gt;</code>    </p>
  
  <p>but then this needs to be changed in all my hibernate.cfg.xml i want to avoid this modification as its a pain ... How can i solve this problem ?</p>
  
  <p>I am using docker-compose which by default creates a network and runs the container in that network i can use container name to establish communication between the containers , but i need to avoid replacing localhost with container name in all my cfg.xml files ..</p>