title: Can't connect to mysql inside docker on osx
body: <p>Lately, my docker container is refusing connections.  It has worked well in the past, this issue is new and has no explanation so far.</p>
  
  <p>Stopping and restarting the container has no effect.<br>
  Stopping and restarting Docker for Desktop for Mac has no effect.</p>
  
  <p>I can resolve it only by rebooting my OSX Laptop.  (macOS Mojave v 10.14.5)
  Then it will work for a while, and then it starts blocking connection attempts again</p>
  
  <p>I can exec into the container, e.g.</p>
  
  <pre><code>docker exec -it db /bin/bash
  </code></pre>
  
  <p>From within the container I can access mysql no problem.</p>
  
  <p>I've tried enabling the general log in mysql to try to debug it:
    It shows no activity... </p>
  
  <p>My laptop has plenty of free disk space (188GB free)</p>
  
  <p>All this worked well for the last 6 months, but just suddenly started blocking connections after working briefly in the last week or so....</p>
  
  <p>Thank you for any clues or ideas</p>
  
  <p>Here is my Dockerfile</p>
  
  <pre><code>FROM mysql:5.7
  
  RUN DEBIAN_FRONTEND=noninteractive apt-get update
  RUN DEBIAN_FRONTEND=noninteractive apt-get install -y apt-utils
  RUN DEBIAN_FRONTEND=noninteractive apt-get install -y procps
  RUN DEBIAN_FRONTEND=noninteractive apt-get install -y debianutils
  RUN DEBIAN_FRONTEND=noninteractive apt-get install -y iputils-ping
  RUN DEBIAN_FRONTEND=noninteractive apt-get install -y net-tools
  RUN DEBIAN_FRONTEND=noninteractive apt-get install -y vim
  RUN DEBIAN_FRONTEND=noninteractive apt-get install -y less
  RUN DEBIAN_FRONTEND=noninteractive apt-get install -y man
  RUN DEBIAN_FRONTEND=noninteractive apt-get install -y sudo
  
  WORKDIR .
  
  COPY ./my.cnf /etc/mysql/my.cnf
  
  #CMD ["mysqld", "--general_log=1", "--log-raw", "--log-error"]
  CMD ["mysqld"]
  </code></pre>
  
  <p>my docker-compose file: </p>
  
  <p>(MYSQL_DATA_FOLDER is an environment variable that is set to a valid path</p>
  
  <pre><code>version: '3.5'
  services:
    database:
      image: database
      ports:
        - "3306:3306"
      environment:
        MYSQL_ROOT_PASSWORD: ""
        MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
      volumes:
        - mydatavolume:${MYSQL_DATA_FOLDER}
      build:
        context: .
  
  volumes:
    mydatavolume:
  
  networks:
    default:
      name: dev_network
      driver: bridge
  </code></pre>
  
  <p>How I start it up:</p>
  
  <pre><code>docker-compose build; 
  docker-compose run --service-ports --volume=$MYSQL_DATA_FOLDER:/var/lib/mysql --name db --rm database
  </code></pre>
  
  <p>How I usually connect (via mysql client in osx terminal)</p>
  
  <pre><code>mysql -h localhost -P 3306 --protocol=tcp -u root
  </code></pre>
  
  <p>I've also tried variations using 127.0.0.1 and also the IP address revealed by docker inspect</p>
  
  <p>My my.cnf</p>
  
  <pre><code>[mysqld]
  sql_mode = ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
  </code></pre>
  
  <p>tried adding:</p>
  
  <pre><code>bind-address=0.0.0.0
  </code></pre>
  
  <p>to the above... doesn't help</p>
  
  <p>users table</p>
  
  <pre><code>mysql&gt; SELECT host, user FROM mysql.user;
  +-----------+---------------+
  | host      | user          |
  +-----------+---------------+
  | %         | root          |
  | %         | some_user     |
  | localhost | mysql.session |
  | localhost | mysql.sys     |
  | localhost | root          |
  +-----------+---------------+
  5 rows in set (0.01 sec)
  </code></pre>
  
  <p>New information:</p>
  
  <p>I have removed the data volume and let it create a new one.  Now the problem is gone - so, it seems to be a MySQL issue and not a Docker issue.  I would still like to know how to debug this kind of MySQL issue when it occurs..</p>