Пытаюсь запустить flask и postgresql в контейнере, но успешно запускается только postgresql, а flask падает с ошибкой:
Traceback (most recent call last):
File "/app/app.py", line 12, in <module>
db.create_all()
*Обновление* Вне докера тоже вылетает данная ошибка
Вот мои файлы:
models.pyfrom datetime import datetime
import flask_sqlalchemy
db = flask_sqlalchemy.SQLAlchemy()
class Quiz(db.Model):
__tablename__ = 'quiz'
id = db.Column(db.Integer, primary_key=True)
question = db.Column(db.String(255))
answer = db.Column(db.String(100))
created = db.Column(db.DateTime, default=datetime.utcnow)
def __repr__(self):
return f"id: {self.id}, answer: {self.answer}, created: {self.created}"
app.pyimport json
from flask import Flask, request
from models import db
import config
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = config.DATABASE_CONNECTION_URI
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.app_context().push()
db.init_app(app)
db.create_all()
# @app.route('/', methods=['GET'])
@app.route('/')
def hello_world():
return 'Flask Dockerized!'
config.pyimport os
user = "tzuser"
password = "password"
host = "postgres"
database = "tzdb"
port = "5432"
DATABASE_CONNECTION_URI = f'postgresql+psycopg2://{user}:{password}@{host}:{port}/{database}'
DockerfileFROM python:3.10
WORKDIR /app
COPY . .
RUN pip install -r requirements.txt
ENTRYPOINT ["python"]
CMD ["app.py"]
docker-compose.ymlversion: '3.9'
services:
app:
build:
context: ./app
ports:
- 5000:5000
volumes:
- ./app:/app
postgres:
image: postgres:13.3
healthcheck:
test: [ "CMD", "pg_isready", "-q", "-d", "postgres", "-U", "tzuser" ]
timeout: 45s
interval: 10s
retries: 10
restart: always
environment:
POSTGRES_DB: tzdb
POSTGRES_USER: tzuser
POSTGRES_PASSWORD: password
ports:
- 5432:5432
volumes:
# - ./db.sql:/docker-entrypoint-initdb.d/db.sql
# - ./postgres-data:/var/lib/postgresql/data
- ./db-data/:/var/lib/postgresql/data/
# - ./init.sql:/docker-entrypoint-initdb.d/init.sql