title: How to connect to mysql docker container from flask application using sql-alchemy
body: <p>I have a flask application. This application is running locally. I have pulled mysql:5.7 and it is running. I want to create a database inside the mysql:5.7 container from the flask application and use that. I am using sql_alchemy.</p>
  
  <p>I have given the uri as </p>
  
  <pre><code>app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root:root@172.17.0.2:4000/document_generator'
  </code></pre>
  
  <p>where root and root are mysql username and password respectively. 172.17.0.2 is the ip address of the mysql container. I have run the container using</p>
  
  <pre><code>docker run  -p 4000:4000  -e MY_SQL_ROOT_PASSWORD=root mysql:5.7
  </code></pre>
  
  <p>I have exposed the port 4000. But, when i get inisde the conatiner and try </p>
  
  <pre><code>show global variables like 'port';
  </code></pre>
  
  <p>it gave 3306 as the port.</p>
  
  <p>I tried using both the ports in the SQL_ALCHEMY_URI, but none of them were able to create the database.I also tried changing mysql:// to mysql+pymsql://. Even that dint work.
  I have written the table creation code inside models.py </p>
  
  <pre><code>class Users(db.Model):
  __tablename__ = 'users'
  username = db.Column(db.String(128), nullable=True)
  password = db.Column(db.String(256), nullable=False)
  private_id = db.Column(db.String(128), primary_key=True)
  </code></pre>
  
  <p>I want the database to be created in the mysql container when i run my flask application. I have no idea about docker-compose. Any help would be of great help. Thanks in advance.</p>