title: Cannot connect to MySQL (python MySql-Connector) when in docker container
body: <p>I have a Python Flask based app that needs to connect to a database </p>
  
  <pre><code>version: "3.7"
  
  networks:
    localdev:
      driver: bridge
  
  services:
    sysman-db:
      image: mysql:8.0
      container_name: sysman-db
      command: --default-authentication-plugin=mysql_native_password
      restart: always
      ports:
        - "4000:3306"
      environment:
        MYSQL_ROOT_PASSWORD: xxxxx
      volumes:
        - ./database/docker:/etc/mysql/conf.d
        - ./database/schema.sql:/docker-entrypoint-initdb.d/dump0.sql
      networks:
        - localdev
  
    sysman:
      build:
        context: .
        dockerfile: Dockerfile.sysman
      container_name: sysman
      depends_on:
        - sysman-db
      ports:
        - "3030:3030"
      networks:
        - localdev
      links:
        - lsm-db
  </code></pre>
  
  <p>The Flask application connects to the MySql, it has a retry method because of Docker bringing up sysman before the database initialisation completes.</p>
  
  <p>Even when the database is up, I am still getting:</p>
  
  <pre><code>sysman    | 2020-02-11 13:55:08 [ERROR] Unable to connect to db, reason: 2003: Can't connect to MySQL server on 'sysman-db:4000' (111 Connection refused)
  sysman    | 2020-02-11 13:55:18 [ERROR] Unable to connect to db, reason: 2003: Can't connect to MySQL server on 'sysman-db:4000' (111 Connection refused)
  sysman    | 2020-02-11 13:55:28 [ERROR] Unable to connect to db, reason: 2003: Can't connect to MySQL server on 'sysman-db:4000' (111 Connection refused)
  sysman    | 2020-02-11 13:55:38 [ERROR] Unable to connect to db, reason: 2003: Can't connect to MySQL server on 'sysman-db:4000' (111 Connection refused)
  </code></pre>
  
  <p>The database connect is:</p>
  
  <pre><code>dbConfig = { 'host' : '127.0.0.1', 'port' : 4000, 'user' : user, 
               'password' : password, 'database' : database }
  connPool = mysql.connector.pooling.MySQLConnectionPool(pool_name='myPool',
                                                         pool_size=3,
                                                         pool_reset_session=True,
                                                         **dbConfig)
  </code></pre>
  
  <p>If I bring up the MySql container on its own then using mysql -u root -p -P 4000 I can connect.</p>