title: Unable to connect to dockerized mysql db remotely
body: <p>On my <code>AWS ec2</code> server I have <code>docker 1.9.1</code> installed.
  In an image <code>test_image</code> based from <code>ubuntu:trusty</code> official docker image, I have tried to setup the LEMP(Linux, Nginx, MySQL, PHP) architecture.</p>
  
  <p>Following is the docker command i have used to start my container:</p>
  
  <pre><code>docker run --name test_1 -d -p 80:80 -p 3306:3306 test_image /bin/sh -c "while true; do echo daemonized docker container; sleep 5000; done"
  </code></pre>
  
  <p>I have exposed port <code>80</code> and <code>3306</code> to the host's network interface and have also allowed AWS's security group to allow inbound connections to these ports. Connection type in security group is: <code>MYSQL/Aurora</code> and protocol is: <code>TCP</code> (I know its not very secure, its only for initial implementation. Production setup will be different)</p>
  
  <p>I followed this DigitalOcean tutorial: <a href="https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-14-04" rel="nofollow">https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-14-04</a></p>
  
  <p>After installing Nginx and starting it I am able to test it in the browser via ec2's pubic ip i.e. <a href="http://xxx.xxx.xxx.xxx" rel="nofollow">http://xxx.xxx.xxx.xxx</a> shows the default nginx welcome page.</p>
  
  <p>While installing MySQL, I followed the following commands in the docker container:</p>
  
  <pre><code>apt-get install mysql-server
  mysql_install_db
  /etc/init.d/mysql start
  mysql_secure_installation
  </code></pre>
  
  <p>I have given a password to my <code>root</code> user and during <code>mysql_secure_installation</code> i had allowed remote access to root user.</p>
  
  <p><code>mysql -u root -p</code> command from inside the container connects me to the mysql db but not from outside the container.</p>
  
  <p>Also from my local machine:
  I tried with mysql-client:
  <code>mysql -h xxx.xxx.xxx.xxx -u root -p</code> </p>
  
  <p>I got the following error: <code>ERROR 2003 (HY000): Can't connect to MySQL server on 'xxx.xxx.xxx.xxx' (111)</code></p>
  
  <p>and also through mysql workbench but I still can't connect to the mysql db.</p>
  
  <p>What am I doing wrong?</p>