title: Connecting Python and MySQL in docker / docker-compose
body: <p>Before, I created named volume and database: 'mysql-db1' using other mysql container.</p>
  
  <p>I can't connect to database from python.</p>
  
  <p>My .yml file : </p>
  
  <pre><code>    version: '3.6'
  
      services: 
        python:
          image: python:latest
          ports:
           - '80:80'
          volumes:
            - type: bind
              source: .
              target: /scripts
          command: tail -f /dev/null
          links:
            - 'mysql'
  
        mysql:
          image: mysql/mysql-server:latest
          ports:
           - '3306:3306'
          environment:
            MYSQL_ROOT_PASSWORD: root
          volumes:
            - type: volume
              source: mysql-db1
              target: /var/lib/mysql
  
  
      volumes: 
        mysql-db1:
          external: true
  </code></pre>
  
  <p>My simply python code: </p>
  
  <pre><code>    import mysql.connector
  
      cnx = mysql.connector.connect(user='root', password='root', host='mysql', database='test1')
      cnx.close()
  </code></pre>
  
  <p>I can enter the database using:</p>
  
  <pre><code>    $ docker-compose exec mysql bash
      # mysql -uroot -proot -Dtest1
  </code></pre>
  
  <p>Error: </p>
  
  <pre><code>    mysql.connector.errors.DatabaseError: 1130 (HY000): Host '172.18.0.3' is not allowed to connect to this MySQL server
  </code></pre>
  
  <p>Where is a problem? </p>