I have two separate container. When I am trying to connect MySQL with my Django container I am getting this error:
django_farhyn | super().__init__(*args, **kwargs2)
django_farhyn | django.db.utils.OperationalError: (2005,
"Unknown server host 'mysql' (-2)")
This docker compose file for mysql , phpmyadmin and using for others services:
version: '3'
services:
mysql:
image: mysql:8
container_name: mysql
environment:
MYSQL_ROOT_PASSWORD: test
MYSQL_USER: test
MYSQL_PASSWORD: test
MYSQL_DATABASE: testdb
ports:
- "3306:3306"
restart: always
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
environment:
PMA_HOST: mysql
MYSQL_ROOT_PASSWORD: test
ports:
- "8080:80"
depends_on:
- mysql
restart: always
This docker compose file for only django project
version: '3'
services:
django_farhyn:
build: .
container_name: django_farhyn
command: python manage.py runserver 0.0.0.0:8000
ports:
- "8000:8000" # Django application port mapping
here my db settings:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': config('MYSQL_DATABASE', default=''),
'USER': config('MYSQL_USER', default=''),
'PASSWORD': config('MYSQL_PASSWORD', default=''),
'HOST': 'mysql',
'PORT': '3306',
}
}
I don’t know where I am doing mistake and struggling from few hours for connect mysql container with my django docker container.