【发布时间】:2020-09-30 18:33:48
【问题描述】:
我的本地主机没有问题,在我的电脑上运行良好 但是在 docker 中没有运行并且这个错误
已连接
def get_database_connection():
"""connects to the MySQL database and returns the connection"""
return mysql.connector.connect(
host=config.MYSQL_HOST,
user=config.MYSQL_USERNAME,
passwd=config.MYSQL_PASSWORD,
db = config.MYSQL_DB_NAME,
port=config.MYSQL_PORT,
charset='utf8'
)
config.py
MYSQL_HOST = "localhost"
MYSQL_USERNAME = "root"
MYSQL_PASSWORD = ""
MYSQL_PORT = 3306
MYSQL_DB_NAME = "newsdb"
---------错误--------
** Operational MODE: preforking ***
build Tables
error --- > 2003 (HY000): Can't connect to MySQL server on 'localhost' (99)
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x55e5696d31a0 pid: 10 (default app)
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
项目结构
app
├── admin
│ ├── api.py
│ ├── config.py
│ ├── db.py
│ ├── __init__.py
│ ├── routes.py
│ ├── static
│ └── templates
├── config.py
├── db.py
├── error_handlers.py
├── __init__.py
├── robots
│ ├── robot_runner.py
│ └── robots.py
├── routes.py
├── schema.sql
├── static
│
├── templates
└── test
Dockerfile
FROM tiangolo/uwsgi-nginx-flask:python3.8
COPY . /app
RUN python -m pip install --upgrade pip
COPY ./requirements.txt /var/www/requirements.txt
RUN apt update && apt install -qy libmariadbclient-dev gcc
RUN pip3 install -r /var/www/requirements.txt
这个项目在我的本地主机上运行,没有问题......只想运行 image docker show error 而不是连接到 mysql ..
【问题讨论】:
标签: python docker dockerfile flask-restful