Can't connect to mySql docker container with JDBC
<p>I use <a href="https://github.com/rhuss/docker-maven-plugin" rel="noreferrer">Docker Maven Plugin</a></p>

<p>When test-integration starts i can connect to mysql on container in terminal with this command:</p>

<pre><code>mysql -h 127.0.0.1 -P 32795 -uroot -p
</code></pre>

<p>and everythings works good but when i want to connect mysql in java app with JDBC with this code:</p>

<pre><code>Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection = DriverManager.getConnection(
    "jdbc:mysql://127.0.0.1:" + System.getProperty("mysqlPort") + "/dashboardmanager",
    "root",
    "root"
);
</code></pre>

<p>i get this error:</p>

<pre><code>org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Cannot create PoolableConnectionFactory (Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)
    at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80) ~[spring-jdbc-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:615) ~[spring-jdbc-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:866) ~[spring-jdbc-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:927) ~[spring-jdbc-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:937) ~[spring-jdbc-4.2.4.RELEASE.jar:4.2.4.RELEASE]
</code></pre>

<p>I tried:</p>

<pre><code>export _JAVA_OPTIONS="-Djava.net.preferIPv4Stack=true"
</code></pre>

<p>and</p>

<pre><code>System.setProperty("java.net.preferIPv4Stack" , "true");
</code></pre>

<p>but nothing changed.</p>

<p><a href="https://github.com/rhuss/docker-maven-plugin" rel="noreferrer">Docker Maven Plugin</a> Conf:</p>

<pre><code>&lt;plugin&gt;
            &lt;groupId&gt;org.jolokia&lt;/groupId&gt;
            &lt;artifactId&gt;docker-maven-plugin&lt;/artifactId&gt;
            &lt;version&gt;${docker-maven-plugin.version}&lt;/version&gt;
            &lt;configuration&gt;
                &lt;images&gt;
                    &lt;image&gt;
                        &lt;name&gt;mysql:5.7.11&lt;/name&gt;
                        &lt;run&gt;
                            &lt;env&gt;
                                &lt;MYSQL_ROOT_PASSWORD&gt;root&lt;/MYSQL_ROOT_PASSWORD&gt;
                                &lt;MYSQL_DATABASE&gt;dashboardmanager&lt;/MYSQL_DATABASE&gt;
                            &lt;/env&gt;
                            &lt;ports&gt;
                                &lt;port&gt;mysqlPort:3306&lt;/port&gt;
                            &lt;/ports&gt;
                        &lt;/run&gt;
                    &lt;/image&gt;
                &lt;/images&gt;
            &lt;/configuration&gt;
            &lt;executions&gt;
                &lt;execution&gt;
                    &lt;id&gt;start&lt;/id&gt;
                    &lt;phase&gt;pre-integration-test&lt;/phase&gt;
                    &lt;goals&gt;
                        &lt;goal&gt;start&lt;/goal&gt;
                    &lt;/goals&gt;
                &lt;/execution&gt;
                &lt;execution&gt;
                    &lt;id&gt;stop&lt;/id&gt;
                    &lt;phase&gt;post-integration-test&lt;/phase&gt;
                    &lt;goals&gt;
                        &lt;goal&gt;stop&lt;/goal&gt;
                    &lt;/goals&gt;
                &lt;/execution&gt;
            &lt;/executions&gt;
        &lt;/plugin&gt;
</code></pre>