Docker Community Forums

Share and learn in the Docker community.

How can i connect django image with a mysql image


(Sakeer) #1

I have found this for connecting my django app with a postgrsql. But i cannot find any documentation for connecting my django app with mysql databse.
Using the docker compose i have created the django app . But i cannot do a mysql connection with it.
Please find below for docker-compose.yml file

dbcon:
  image: sakeer/mysql_connection_django
  ports:
    - 3308:3306
  environment:
    MYSQL_ALLOW_EMPTY_PASSWORD: 'True'
    MYSQL_DATABASE: 'blog'
    MYSQL_ROOT_PASSWORD: 'sakeer123'
web:
  build: .
  command: python manage.py runserver 0.0.0.0:8000
  volumes:
    - .:/code
  ports:
    - "8000:8000"
  links:
    - dbcon 

And my databse setting under settings.py is,

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'blog',
        'USER': '',
        'PASSWORD': 'sakeer123',
        'HOST': 'dbcon',
        'PORT': 3308,
    }
}

My mysql image is residing in the sakeer/mysql_connection_django docker image
When i am running the docker-compose up command i am getting the following error,

web_1   | django.db.utils.OperationalError: (2003, "Can't connect to MySQL server on 'dbcon' (111)")