我的发行版是ubuntu
烧瓶无法识别在docker-compose中创建的密码
运行docker-compose时出现以下错误
(1045,“拒绝访问用户'user'@'172.23.0.3'(使用密码:是)”)
docker-compose.yml
version: '3'
services:
web:
build: .
command: python /code/app/app.py
ports:
- "8000:8000"
volumes:
- .:/code
links:
- db
db:
image: mysql:5.7
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: "roott"
MYSQL_DATABASE: "MYFLASKK"
MYSQL_USER: "user"
MYSQL_PASSWORD: "password"
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
Dockerfile
FROM python:3.5-alpine
ADD . /code
WORKDIR /code/
RUN pip install -r requirements.txt
EXPOSE 8000
app.py
from flask import Flask, render_template, request, url_for, redirect
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://user:password@db:3306/MYFLASKK'
db = SQLAlchemy(app)
class Funcionario(db.Model):
__tablename__='funcionario'
_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
nome = db.Column(db.String(50))
def __init__(self, nome, email):
self.nome = nome
db.create_all()
if __name__ == "__main__":
app.run(debug=True) ```