I'm having a trouble on how to configure my application to integrate Flask, PonyORM, and MySQL using docker and docker-compose.
This is my .yml
file:
version: '3.1'
services:
mysql:
image: mysql
restart: always
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: kofre.db
adminer:
image: adminer
restart: always
ports:
- 8080:8080
python:
build: .
volumes:
- .:/kofre-app
ports:
- 5000:5000
depends_on:
- mysql
This is my Dockerfile:
FROM python:3
ENV PYTHONBUFFERED 1
RUN mkdir /kofre-app
WORKDIR /kofre-app
COPY setup.py /kofre-app/
RUN python setup.py install
COPY . /kofre-app/
CMD [ "python", "./run.py" ]
and this is a part of my Pony initialization script:
app = Flask(__name__)
app.config.from_object('config')
db = Database()
db.bind(provider = 'mysql', host = 'mysql', user = 'root', passwd = 'root', db = 'kofre.db')
My problems:
- Sometimes when I run the command
docker-compose up
I'm getting the message: "Can't connect to MySQL server on 'mysql' (timed out)". Is it a proble with PonyORM? Should I use another framework? - And sometimes, the
mysql
service seems to lock the prompt and nothing happens after that.
Could someone help me with this problems? I'd appreciate your help.