Alright so been trying for a while to get this to work. Here is the line of commands I run from start to finish and I get an Access denied... error shown below.
$ 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)") Here is the repo https://github.com/Amertz08/flask-docker
It looks like the SqlAlchemy engine is not looking at the right container. 'flask-docker'@'flaskdocker_web_1.flaskdocker_default' is what shows up in the error.
Maybe I am not understanding it right but I linked mysql:mysql in my docker-compose.yml file
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 Then in my config object in config.py I have the following...
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 ) Any help on this would be greatly appreciated.
mysql. You don't need to refer to it asflask_docker. Also, you can just saymysqlinstead ofmysql:mysql. The latter form is only needed when you map a container under a different name (e.g.,mysql:flask_docker).