Unable to Connect MySQL container to Tomcat Container in docker
<p><strong>The Plan</strong></p>

<p>I want my tomcat server to be able to connect to my MySQL server both in separate containers.</p>

<p><strong>The Problem</strong></p>

<p>Tomcat cannot connect to MySQL</p>

<p>I used some of the details from the <a href="https://docs.docker.com/compose/wordpress/" rel="nofollow noreferrer">wordpress tutorial</a> about setting up a link with the mysql container and created the link to the MySQL.</p>

<p>Although the tomcat and mysql spin up just fine I can't seem to get tomcat to be able to connect to MySQL, the settings work on my local machine perfectly fine.</p>

<p>I've attempted to use <code>--net: "host"</code> as well although that does not work with Tomcat as it throws a severe error.</p>

<p><strong>Previous answers</strong></p>

<p>I <a href="https://stackoverflow.com/a/10772407/3746816">noticed on this post a load</a> of possible fixes for the error although I don't believe any of these would translate to my problem as I believe this is a docker problem not a host one.</p>

<p><strong>docker-compose.yml</strong></p>

<pre><code>web:
  image: tomcat:7.0
  container_name: tomcat-container
  ports:
   - "80:8080"
  hostname: docker-tomcat
  volumes:
   - /home/webapps:/usr/local/tomcat/webapps
  links:
   - db
db:
  image: mysql
  container_name: mysql-container
  environment:
   MYSQL_ROOT_PASSWORD: Mysqlpassword1
   MYSQL_DATABASE: tracker
  volumes:
   - /home/mysqlDB:/var/lib/mysql
</code></pre>

<p>This is my <code>Context.xml from tomcat.</code></p>



<pre><code>&lt;Context&gt;
    &lt;Resource
        name="jdbc/tracker" type="javax.sql.DataSource"
        maxActive="100" maxIdle="30" maxWait="10000" 
        url="jdbc:mysql://localhost:3306/tracker?useSSL=false"
        driverClassName="com.mysql.jdbc.Driver"
        username="root" password="mysqladmin1"
    /&gt;
    &lt;Resource
        name="jdbc/jenkins" type="javax.sql.DataSource"
        maxActive="100" maxIdle="30" maxWait="10000" 
        url="jdbc:mysql://localhost:3306/jenkins?useSSL=false"
        driverClassName="com.mysql.jdbc.Driver"
        username="root" password="mysqladmin1"
    /&gt;
&lt;/Context&gt;
</code></pre>

<p>The error code.</p>

<pre><code>The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
at databaseConnections.SQLDatabaseConnection.tableExists(SQLDatabaseConnection.java:131)
at databaseConnections.JiraSQLDatabaseConnection.&lt;init&gt;(JiraSQLDatabaseConnection.java:50)
</code></pre>