So i have Dockerized a python app that writes data to mysql database, but it seems that everytime i start the app inside the container with this command:
python main.py -d database -l user -p password
get (2002, “Can’t connect to local MySQL server through socket ‘/run/mysqld/mysqld.sock’ (111)”)
i build the container with:
docker build -t name_of_image:tag .
and run it with network host so it uses the same network as the localhost:
docker run -td --network="host" name_of_imae:tag
I tried multiple approach: executing it into micro-services with docker-compose and connecting my app with mysql/mariadb image, and same network. doesn’t work.
really frustrating…
i share with you my requirments.txt and my Dockerfile:
FROM python:3.8
WORKDIR /usr/src/app/
# Installing Python and all the dependencies
COPY requirements.txt ./
RUN pip3 install --no-cache-dir -r requirements.txt
COPY . .
# Dependencies for Copilot XMPP
twisted==21.7.0
defer==1.0.4
redis
lxml==4.7.1
spyne==2.13.16
PyMySQL==1.0.2
mysql-connector==2.2.9
mysqlclient==2.1.0
requests==2.27.1
#''' Twisted TLS Extra '''
pyOpenSSL==21.0.0
service-identity==21.1.0
idna==2.8
It uses multple service but it doesn’t concern me as much as the mysql writing data hope somone can help.