1

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.

Ploxer
  • 13
  • 2

1 Answers1

0

There are multiple ways of achieving this. Most of them are discussed in this other SO topic.

I think one of the easiest ways to achieve this would be to point from your docker container to the host using the built-in DNS name:

host.docker.internal

The chosen option would depend on the version of docker you use. Check the linked issue for more information.

JustLudo
  • 1,690
  • 12
  • 29