好了,所以一直尝试使它起作用.这是我从头到尾运行的命令行,并且出现访问拒绝…错误,如下所示.
$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
)
任何帮助,将不胜感激.