好了,所以一直尝试使它起作用.这是我从头到尾运行的命令行,并且出现访问拒绝…错误,如下所示.
$docker-compose up --build -d
$docker exec -it flaskdocker_MysqL_1 MysqL -u root -p
MysqL> CREATE DATABASE flask_docker;
MysqL> CREATE USER `flask-docker`@`localhost` IDENTIFIED BY 'pass';
MysqL> GRANT ALL PRIVILEGES ON flask_docker.* TO 'flask-docker'@'localhost';
MysqL> exit
Bye
$docker exec -it flaskdocker_web_1 python /usr/src/app/manage.py createdb
# rest of traceback
sqlalchemy.exc.OperationalError: (pyMysqL.err.OperationalError) (1045,u"Access denied for user 'flask-docker'@'flaskdocker_web_1.flaskdocker_default' (using password: YES)")
这是回购https://github.com/Amertz08/flask-docker
看起来sqlAlchemy引擎没有查看正确的容器.错误中显示的是’flask-docker’@’flaskdocker_web_1.flaskdocker_default’.
也许我不太了解它,但是我在docker-compose.yml文件中链接了MysqL:MysqL
web:
restart: always
build: ./app
volumes:
- /usr/src/app/static
expose:
- "5000"
environment:
FLASK_CONFIG: 'production'
links:
- MysqL:MysqL
command: /usr/local/bin/uwsgi --ini uwsgi.ini
然后在config.py中的配置对象中,我有以下内容…
MysqL_USER = 'flask-docker'
MysqL_PASS = 'pass'
MysqL_HOST = 'MysqL'
MysqL_DB = 'flask_docker'
# Database info
sqlALCHEMY_DATABASE_URI = 'MysqL+pyMysqL://{usr}:{passwd}@{host}/{db}'.format(
usr=MysqL_USER,passwd=MysqL_PASS,host=MysqL_HOST,db=MysqL_DB
)
任何帮助,将不胜感激.
最佳答案
原文链接:https://www.f2er.com/docker/532667.html