Web_1 | MySQLdb._exceptions.OperationalError: (2002, "Не удается подключиться к локальному серверу MySQL через сокет '/var/run/mysqld/mysqld.sock' (2)")
Я создаю приложение с Djnago и MySql. Я хочу использовать docker для развертывания моего приложения. Я подготовил файл requirement.txt, docker-compose.yml и Dockerfile docker-compose.yml
version: '3'
services:
db:
image: mariadb
restart: always
ports:
- 3306:3306
environment:
MYSQL_DATABASE: stage_emsi
MYSQL_USER: root
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: password
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
ports:
- "8000:8000"
volumes:
- .:/code
depends_on:
- db
image: web:django
Dockerfile
FROM python:3
ENV PYTHONUNBUFFERED=1
RUN mkdir /code
WORKDIR /code
RUN pip install mysqlclient
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/
ошибка
b_1 | Watching for file changes with StatReloader
web_1 | Performing system checks...
web_1 |
web_1 | System check identified no issues (0 silenced).
web_1 | Exception in thread django-main-thread:
web_1 | Traceback (most recent call last):
web_1 | File "/usr/local/lib/python3.9/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
web_1 | self.connect()
web_1 | File "/usr/local/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner
web_1 | return func(*args, **kwargs)
web_1 | File "/usr/local/lib/python3.9/site-packages/django/db/backends/base/base.py", line 200, in connect
web_1 | self.connection = self.get_new_connection(conn_params)
web_1 | File "/usr/local/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner
web_1 | return func(*args, **kwargs)
web_1 | File "/usr/local/lib/python3.9/site-packages/django/db/backends/mysql/base.py", line 234, in get_new_connection
web_1 | connection = Database.connect(**conn_params)
web_1 | File "/usr/local/lib/python3.9/site-packages/MySQLdb/__init__.py", line 130, in Connect
web_1 | return Connection(*args, **kwargs)
web_1 | File "/usr/local/lib/python3.9/site-packages/MySQLdb/connections.py", line 185, in __init__
web_1 | super().__init__(*args, **kwargs2)
web_1 | MySQLdb._exceptions.OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")
Проверьте настройки подключения к базе данных вашего приложения Django. Похоже, что вы пытаетесь подключиться через локальный файл сокета Linux, а не к IP-адресу базы данных MySQL.