好了,所以一直尝试使它起作用.这是我从头到尾运行的命令行,并且出现访问拒绝…错误,如下所示.
$docker-compose up --build -d
$docker exec -it flaskdocker_@R_301_198@_1 @R_301_198@ -u root -p
@R_301_198@> CREATE DATABASE flask_docker;
@R_301_198@> CREATE USER `flask-docker`@`localhost` IDENTIFIED BY 'pass';
@R_301_198@> GRANT ALL PRIVILEGES ON flask_docker.* TO 'flask-docker'@'localhost';
@R_301_198@> exit
Bye
$docker exec -it flaskdocker_web_1 python /usr/src/app/manage.py createdb
# rest of traceback
sqlalchemy.exc.OperationalError: (py@R_301_198@.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文件中链接了@R_301_198@:@R_301_198@
web:
restart: always
build: ./app
volumes:
- /usr/src/app/static
expose:
- "5000"
environment:
FLASK_CONFIG: 'production'
links:
- @R_301_198@:@R_301_198@
command: /usr/local/bin/uwsgi --ini uwsgi.ini
然后在config.py中的配置对象中,我有以下内容…
@R_301_198@_USER = 'flask-docker'
@R_301_198@_PASS = 'pass'
@R_301_198@_HOST = '@R_301_198@'
@R_301_198@_DB = 'flask_docker'
# Database info
sqlALCHEMY_DATABASE_URI = '@R_301_198@+py@R_301_198@://{usr}:{passwd}@{host}/{db}'.format(
usr=@R_301_198@_USER,passwd=@R_301_198@_PASS,host=@R_301_198@_HOST,db=@R_301_198@_DB
)
任何帮助,将不胜感激.
最佳答案
原文链接:https://www.f2er.com/docker/532667.html