title: Aborted connection to db; docker-compose ruby & mysql images - Got an error reading communication packets
body: <p>I'm using docker-compose to run a rails app with mysql db docker image. </p>
  
  <p>The <strong>docker-compose build</strong> goes fine; the <strong>docker-compose up</strong> goes fine as well, even though there are some warnings (mysql image version issues)</p>
  
  <pre><code>...
  db_1 | MySQL init process done. Ready for start up.
  db_1 | [Warning] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key
  ...
  db_1 | [Warning] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
  db_1 | [Warning] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
  db_1 | [Warning] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
  db_1 | Version: '5.7.10' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server (GPL)
  db_1 | Version: '5.7.10' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server (GPL)
  web_1 | [2016-02-11 18:38:10] INFO WEBrick 1.3.1
  web_1 | [2016-02-11 18:38:10] INFO ruby 2.2.0 (2014-12-25) [x86_64-linux]
  web_1 | [2016-02-11 18:38:10] INFO WEBrick::HTTPServer#start: pid=1 port=3000
  </code></pre>
  
  <p>When I run migration commands <strong>docker-compose run web rake db:create|migrate</strong> on another terminal, I get this errors, in the current one (<strong>docker-compose up</strong>):</p>
  
  <pre><code>db_1 | [Note] Aborted connection 2 to db: 'unconnected' user: 'root' host: '172.17.0.4' (Got an error reading communication packets)
  ...
  db_1 | [Note] Aborted connection 3 to db: 'unconnected' user: 'root' host: '172.17.0.4' (Got an error reading communication packets)
  </code></pre>
  
  <p>This is my <strong><em>Dockerfile</em></strong>:</p>
  
  <pre><code>FROM ruby:2.2.0
  RUN apt-get update -qq &amp;&amp; apt-get install -y build-essential
  RUN mkdir /myapp
  WORKDIR /myapp
  ADD Gemfile /myapp/Gemfile
  ADD Gemfile.lock /myapp/Gemfile.lock
  RUN bundle install
  ADD . /myapp
  EXPOSE 3000
  </code></pre>
  
  <p>This is my <strong><em>docker-compose.yml</em></strong>:</p>
  
  <pre><code>    db:
    image: mysql:latest
    environment:
      MYSQL_ROOT_PASSWORD: password
  web:
    build: .
    command: bundle exec rails s -p 3000 -b '0.0.0.0'
    volumes:
      - .:/myapp
    ports:
      - "3000:3000"
    links:
      - db
  </code></pre>
  
  <p>This is my <strong><em>database.yml</em></strong>:</p>
  
  <pre><code>default: &amp;default
    adapter: mysql2
    pool: 5
    encoding: utf8
    host: db
    username: root
    password: password    
  development:
    &lt;&lt;: *default
    database: myapp_development
  test:
    &lt;&lt;: *default
    database: myapp_test
  </code></pre>
  
  <p>For more details, see the <a href="https://gist.github.com/embasbm/0fa8c1aa469c921ddcd3" rel="noreferrer">entire scenario</a></p>