Hi I am using flask and MySQL it works on my local machine perfectly but I want to put it in docker container I get the following error: MySQLdb._exceptions.OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)") Can someone please help me, where I am doing wrong? my dockderfile:
FROM python:3.9
EXPOSE 5000
WORKDIR /virtual-staging
RUN apt-get update
RUN apt-get -y install python3 python3-pip vim iputils-ping python3-mysqldb
# COPY requirements.txt app.py config.py /virtual-staging/
COPY . /virtual-staging
RUN pip install -r requirements.txt
CMD [ "flask", "run", "--host=0.0.0.0"]
and my docker-compose.yml file:
version: "3.7"
services:
app:
build: .
restart: always
links:
- "db"
ports:
- "5000:5000"
environment:
- FLASK_ENV= production
db:
image: mysql:8.0
ports:
- "32000:3306"
restart: always
environment:
MYSQL_ROOT_PASSWORD: root
volumes:
- ./db:/docker-entrypoint-initdb.d/:ro
any my config.py file:
class ProductionConfig(Config):
MYSQl_USER = 'root'
MYSQL_PASSWORD = 'root'
MYSQL_HOST = "mysql"
MYSQL_PORT = "3306"
MYSQL_DB = "virtualstaging"
thank you in advance