I'm trying to dockerize my Django app with Docker, but having some trouble connecting with the mysql database since i'm not really experienced with Docker. I have a couple questions:
I have installed mysql and set up the database locally on my computer, do i have to use a mysql image and create a db service in my docker-compose too ? Shouldn't Django connect to mysql normally like it did when it wasn't dockerized ?
If a database is hosted on a server then is mysql installed on that server ? Do i have to use a mysql image to connect to the database ?
Here is my docker-compose.yml:
version: '3.7'
services:
web:
build: ./appchat
command: python appchat/manage.py runserver
ports:
- 8000:8000
- "3306"
network_mode: "host"
And here is the database settings in settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'USER': 'root',
'PASSWORD': 'root',
'NAME': 'company',
'PORT': '3306',
}
}
Here is the error when i ran docker-compose file:
django.db.utils.OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")
Any help would be appreciated. Thank you.