title: "Reading initial communication packet" error while trying to connect to a mysql docker container from the host
body: <p>I'd like to be able to connect to my docker container as if MySQL server were installed on my local machine. I test my connection with:</p>
  
  <pre><code>mysql -u root -proot -h 127.0.0.1 -P 3306 --protocol=tcp
  </code></pre>
  
  <p>If I create a container using docker, I can successfully do it. Like this:</p>
  
  <pre><code>docker run --name some-mysql-standalone -p 127.0.0.1:3306:3306 -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7.29
  </code></pre>
  
  <p>If I use a container as a service in docker-compose, I get an error:</p>
  
  <pre><code>ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 2
  </code></pre>
  
  <p>MySQL server is running inside the container and I can access it.</p>
  
  <p>My docker compose snippet:</p>
  
  <pre><code>version: '2'
  
  services:
  
      mysql:
  
          image: mysql:5.7.29
          container_name: some_mysql
          restart: unless-stopped
  
          volumes:
              - ./mysql/data:/var/lib/mysql
              - ./mysql/init:/docker-entrypoint-initdb.d
  
          ports:
              - 3306:3306
  
          environment:
              MYSQL_DATABASE: some_mysql
              MYSQL_USER: root
              MYSQL_PASSWORD: root
              MYSQL_ROOT_PASSWORD: root
  </code></pre>
  
  <p>The interesting part is that I've been using this <code>docker-compose.yml</code> for some time now without any issues. I'm not really sure what's changed about my environment that caused it to stop working. </p>
  
  <p>How can I make my mysql container in docker-compose accessible from the host machine?</p>