title: connect to docker mysql from host machine
body: <p>I have docker-compose (showing just MySQL part):</p>
  
  <pre><code>  site_mysql:
      image: site/mysql:latest
      build: ./images/mysql
      environment:
        MYSQL_ROOT_PASSWORD: secret
      volumes:
        -  site_mysqldata:/var/lib/mysql
      networks:
        -  site_appnet
      ports:
        - "3306:3306"
  </code></pre>
  
  <p>I can connect to MySQL from inside the container, but I can't from localhost, the error I'm getting is <strong>Host site_mysql is unknown.</strong></p>
  
  <p>docker file is:</p>
  
  <pre><code>FROM mysql:5.7
  
  MAINTAINER Author
  
  # The official MySQL docker image will run all .sh and .sql scripts found in this directory
  # the first time the container is started.
  COPY init.sql /docker-entrypoint-initdb.d
  COPY my.cnf /etc/mysql/conf.d
  </code></pre>
  
  <p>my.cnf:</p>
  
  <pre><code>[mysqld]
  # Always use UTC
  default-time-zone='+00:00'
  
  # To turn off strict mode (alas, we started out that way, will be work to turn it on)
  sql-mode="NO_ENGINE_SUBSTITUTION"
  
  max-allowed-packet = 16M
  
  ### Per-thread Buffers
  sort-buffer-size = 2M
  read-buffer-size = 128K
  read-rnd-buffer-size = 256K
  join-buffer-size = 256K
  
  ### Temp Tables
  tmp-table-size = 64M
  max-heap-table-size = 64M
  
  #### Storage Engines
  default-storage-engine = InnoDB
  innodb = FORCE
  </code></pre>
  
  <p>init.sql :</p>
  
  <pre><code>CREATE DATABASE IF NOT EXISTS site;
  CREATE DATABASE IF NOT EXISTS site_test;
  CREATE USER 'site'@'%' IDENTIFIED BY 'secret';
  GRANT ALL PRIVILEGES ON site.* TO 'site'@'%' WITH GRANT OPTION;
  FLUSH PRIVILEGES;
  </code></pre>
  
  <p>I'm using the same configuration for a while with different projects and all was okay until now. Any ideas why my host can't recognize <code>site_mysql</code>?</p>
  
  <p><strong>Updated</strong></p>
  
  <p>Also, I have :</p>
  
  <pre><code>  site_memcached:
      image: memcached:1.4-alpine
      networks:
        -  videosite_appnet
  </code></pre>
  
  <p>and here I can connect using <code>site_memcached</code> as a name of the host</p>