Docker Community Forums

Share and learn in the Docker community.

MySQL with Python app

Hi guys, I’m having some troubles with a pyhton app that uses MySQL database.
Everytime I want to connect to the database through the python app I get this error:

_mysql_exceptions.OperationalError: (2003, "Can't connect to MySQL server on '127.0.0.0' (101)")

I am using a container with this Dockerfile.


WORKDIR /app

# Copy the current directory contents into the container at /app
ADD . /app

# Instalacion de las dependencias
RUN pip install -r requirements.txt

The app it’s really basic.
To build this I am using
docker build -t xsschallenge .
and for running it
docker run -ti xsschallenge /bin/bash
for the MySQL part, using a docker-compose.yml

version: '3.1'

services:

  db:
    image: mysql
    environment:
      MYSQL_ROOT_PASSWORD: "temp662237"
    ports:
      - "3306:3306"
    volumes:
      - my-datavolume:/var/lib/mysql
volumes:
  my-datavolume:

And here using docker-compose run --service-ports db

The database connector is
self.conn = _mysql.connect(user=self.user,passwd=self.password,host=self.host,db=self.db,port=3306)

I read a lot this days but I can’t find the solution.

Its not clear if the python container and mysql container is in same network. I would first check if the db container name is pingable from python container and start debug from there.

How run python script with MySql or mariaDb in docker container on raspberry pi 3 b stretch armhf
docker pull mysql (not working)
docker pull mariadb (not working)
Any idea???
To start from scratch
Using Dockerfile or docker-compose.yml