admin管理员组文章数量:1122846
I'm running two docker containers one is mysql db and the other one is flask app , the issue is once i'm imitating a migration i get the error access denied for user followed by the ip of the flask container (MySQLdb._exceptions.OperationalError) (1045, "Access denied for user 'alex'@'172.18.0.3' (using password: YES)")
here's what i've tried so far :
Created a new user instead of root and set the privileges and a new password.
Added both containers the mysql one and the flask one to the bridge network.
Added the address-bind = 0.0.0.0
Tried to connect from inside the flask container manually and it worked somehow which is interesting.
The issue that i have is that i keep getting the error that the access is denied for my user and it's giving me the IP of the flask container which is weird and i've added that sprcific IP as a host to the mysql.user and still no luck and i've also added the user with '%' and localhost and still with no luck.
Here's the error : sqlalchemy.exc.OperationalError: (MySQLdb._exceptions.OperationalError) (1045, "Access denied for user 'alex'@'172.18.0.3' (using password: YES)")
docker file :
FROM python:3.10.9
ENV PYTHONBUFFERED 1
WORKDIR /app
COPY requirements.txt /app/requirements.txt
RUN pip install -r requirements.txt
COPY ./ app
CMD ["python", "main.py"]
docker compose file :
services:
backend :
environment:
- FLASK_APP=main.py
build:
context: .
dockerfile: Dockerfile
ports:
- 8001:5000
volumes:
- .:/app
depends_on:
- db
db:
image: mysql:8.0.39
restart: always
environment:
MYSQL_DATABASE: main
#MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_USER: alex
MYSQL_PASSWORD: root_password
MYSQL_ROOT_PASSWORD: root_pass
volumes:
- .dbdata:/var/lib/mysql
ports:
- 33069:3306
main flask app :
from flask import Flask
from flask_cors import CORS
from flask_migrate import Migrate
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import UniqueConstraint
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://alex:root_password@db:3306/main'
CORS(app)
db = SQLAlchemy(app)
migrate = Migrate(app, db)
print(app.config['SQLALCHEMY_DATABASE_URI'])
class Product(db.Model):
id = db.Column(db.Integer, primary_key=True, autoincrement=False)
title = db.Column(db.String(200))
image = db.Column(db.String(200))
class ProductUser(db.Model):
id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer)
product_id = db.Column(db.Integer)
UniqueConstraint('user_id', 'product_id', name='product_user_unique')
@app.route('/')
def index():
return 'Hello'
print(app.config['SQLALCHEMY_DATABASE_URI'])
if __name__ == '__main__':
app.run(debug=True , host='0.0.0.0')
本文标签: pythonAccess denied for user flask containerStack Overflow
版权声明:本文标题:python - Access denied for user flask container - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736283434a1926967.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论