'How to connect my program in Docker with local databese MySQL [duplicate]

On my Ubuntu20 I have configured MySQL and i have written a python program to communicate with database. I would like to run the Python program in the docker so that it can communicate with the database located locally in the system. Below I paste my Dockerfile content.

Dockerfile:

FROM python:3.8

WORKDIR /my_service

COPY requirements.txt .
RUN pip install -r requirements.txt

COPY ./app ./app

CMD ["python", "./app/main.py"]

But when I run command to run docker conteiner:

sudo docker run -t -p 13000:13000 my_service

My application inside tell me that cant connect to MySQL database. How Could I fix it? I mappped port 13000 because my aplication use it to tcp communication.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source