how to us peewee and mysql using docker?

Viewed 735

I am trying to connect to a Mysql databas using Docker but I have this following error:

peewee.ImproperlyConfigured: MySQL driver not installed!

This is my Dockerfile

FROM python:3.7
ENV PYTHONUNBUFFERED 1

WORKDIR /app

COPY . /app

RUN pip install peewee
RUN python create_db.py

This is my docker-compose.yml

version: '3.3'

services:

    app-mariadb:
        image: mariadb:10.4     
        container_name: app-mariadb                
        ports:
            - "3320:3306"
        environment:
            MYSQL_ROOT_PASSWORD: helloWORLD123
            MYSQL_DATABASE: sp_odesi
            MYSQL_USER: root
            MYSQL_PASSWORD: helloWORLD123

    app-python:
        build: .        
        container_name: app-python      
        command: python create_db.py
        restart: always        
        working_dir: /app
        depends_on:
            - app-mariadb
        volumes:
            - ./:/app
        environment:
            MYSQL_HOST: db
            MYSQL_DATABASE: sp_odesi
            MYSQL_USER: root
            MYSQL_PASSWORD: helloWORLD123
            MYSQL_PORT: 3306
            DATABASE: MARIADB

create_db.py

from peewee import *
from datetime import datetime
import os


db = MySQLDatabase(
        "sp_odesi",user="root",
        passwd="helloWORLD123",port=3306
    )

class Surveys(Model):
    """Surveys

    """
    survey_name     = CharField(max_length=100, unique=True, null=False)

    class Meta:
        database = db

if __name__ == '__main__':
    Surveys.create_table()
    print("Create table")
1 Answers
Related