我正在尝试使用Docker连接到Mysql数据库,但是出现以下错误:
peewee.ImproperlyConfigured: MySQL driver not installed!
这是我的Dockerfile
FROM python:3.7
ENV PYTHONUNBUFFERED 1
WORKDIR /app
COPY . /app
RUN pip install peewee
RUN python create_db.py
这是我的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")
您required a mysql client library to be installed。从[]更改Dockerfile中的以下行
RUN pip install peewee PyMySQL
到
RUN pip install peewee