Cannot connect to MySQL docker container from container with Django app
<p>When I try to connect from a docker container running my Django app to a container running MySQL, I get the following error:</p>

<pre><code>django.db.utils.OperationalError: (2003, "Can't connect to MySQL server on '172.17.0.2' (111)")
</code></pre>

<p>Here's how I'm running the MySQL container:</p>

<pre><code>$ docker run --name mysql -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=testdb -e MYSQL_ROOT_HOST=172.17.0.2 -d mysql/mysql-server:5.7
</code></pre>

<p>If I don't specify <code>MYSQL_ROOT_HOST</code>, I get this error when I try to connect from the container with the Django app:</p>

<pre><code>django.db.utils.OperationalError: (1130, "Host '172.17.0.3' is not allowed to connect to this MySQL server")
</code></pre>

<p>Here are my Django settings:</p>

<pre><code>DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'testdb',
        'USER': 'root',
        'PASSWORD': 'root',
        'HOST': '172.17.0.2',
        'PORT': '',
    }
}
</code></pre>

<p>I've verified the MySQL container is using IP 172.17.0.2:</p>

<pre><code>$ docker inspect mysql |grep -i ipaddress
            "SecondaryIPAddresses": null,
            "IPAddress": "172.17.0.2",
                    "IPAddress": "172.17.0.2",
</code></pre>