title: Django can't connect to mysql via docker-compose
body: <p>I have an application using Django and MySQL. The application does not connect to MySQL container from the Django Application but it can be accessed using Sequel Pro with the same credentials.</p>
  
  <p>This is my docker-compose.yml</p>
  
  <pre><code>version: '2'
  
  services:
    db:
      image: mysql:5.7.18
      ports:
        - "3307:3306"
      volumes:
        - "./mysql:/var/lib/mysql"
      command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
      environment:
        - MYSQL_ROOT_PASSWORD=pass
        - MYSQL_DATABASE=django
        - MYSQL_USER=django
        - MYSQL_PASSWORD=pass
  
    web:
      build:
        context: .
      depends_on:
        - db
  #    links:
  #      - db
      volumes:
        - "./app:/src"
      command: bash -c "sleep 3 &amp;&amp; python3 src/manage.py runserver 8000"
      ports:
        - "8001:8000"
      environment:
        - DJANGO_SETTINGS_MODULE=app.production
        - DB_NAME=django
        - DB_USER=django
        - DB_PASS=pass
        - DB_HOST=db
        - DB_PORT=3306
  </code></pre>
  
  <p>This is my django settings.py</p>
  
  <pre><code>DATABASES = {
      'default': {
          'ENGINE': 'django.db.backends.mysql',
          'NAME': os.getenv('DB_NAME', 'django'),
          'USER': os.getenv('DB_USER', 'django'),
          'PASSWORD': os.getenv('DB_PASS', 'pass'),
          'HOST': os.getenv('DB_HOST', 'db'),
          'PORT': os.getenv('DB_PORT', '3306'),
          'OPTIONS': {
              'sql_mode': 'STRICT_TRANS_TABLES',
          }
      }
  }
  </code></pre>
  
  <p>And this is error that I don't know how to fix this</p>
  
  <pre><code>web_1    | Performing system checks...
  web_1    |
  web_1    | Unhandled exception in thread started by &lt;function check_errors.&lt;locals&gt;.wrapper at 0x7efeb8563950&gt;
  web_1    | Traceback (most recent call last):
  web_1    |   File "/usr/local/lib/python3.5/dist-
  packages/django/db/backends/base/base.py", line 213, in ensure_connection
  web_1    |     self.connect()
  web_1    |   File "/usr/local/lib/python3.5/dist-
  packages/django/db/backends/base/base.py", line 189, in connect
  web_1    |     self.connection = self.get_new_connection(conn_params)
  web_1    |   File "/usr/local/lib/python3.5/dist-
  packages/django/db/backends/mysql/base.py", line 274, in get_new_connection
  web_1    |     conn = Database.connect(**conn_params)
  web_1    |   File "/usr/local/lib/python3.5/dist-
  packages/MySQLdb/__init__.py", line 86, in Connect
  web_1    |     return Connection(*args, **kwargs)
  web_1    |   File "/usr/local/lib/python3.5/dist-packages/MySQLdb/connections.py", line 204, in __init__
  web_1    |     super(Connection, self).__init__(*args, **kwargs2)
  web_1    | _mysql_exceptions.OperationalError: (2003, "Can't connect to MySQL server on 'db' (110)")
  </code></pre>
  
  <p>Please advice I don't know what I do mistake.</p>
  
  <p>Update: I just see that my container can't send request to sentry.io too</p>
  
  <pre><code>Sentry responded with an error: &lt;urlopen error [Errno -3] Temporary failure in name resolution&gt; (url: https://sentry.io/api/210137/store/)
  </code></pre>
  
  <p>So This is about docker network? How do I investigate this problem thanks</p>