title: How to connect to docker container from eclipse using jdbc
body: <p>I have downloaded the docker image <code>mysql/mysql-server</code> from docker hub and ran a container using the command:</p>
  
  <p><code>docker run --name &lt;name of my container&gt; -e MYSQL_ROOT_PASSWORD=&lt;my pwd &gt; -d mysql:mysql-server</code></p>
  
  <p>I have opened <code>mysql</code> in interactive mode using command <code>docker exec -it &lt;name of my container&gt; mysql -uroot -p</code> and created a database, table and granted all its privileges to my machine ip using following commands:</p>
  
  <pre><code>mysql&gt; create user 'uname'@'&lt;machine ip&gt;' identified by 'pwd'; 
  mysql&gt; create database &lt;dbname&gt;; 
  mysql&gt; grant all privileges on &lt;dbname&gt;. * to 'uname'@'&lt;machine ip&gt;' identified by '&lt;pwd&gt;';  
  mysql&gt; flush privileges; 
  </code></pre>
  
  <p>I opened my eclipse and created a db connection using <code>data source explorer</code> and connected using <code>jdbc:mysql://&lt;container ip&gt;:3306/dbname</code>. When I test my connection it is saying:</p>
  
  <blockquote>
    <p>Connection timed out</p>
  </blockquote>
  
  <p>Could any one suggest where I am making the mistake?</p>