Привет всем, я пытаюсь докернизировать приложение django с подключением к базе данных. когда я запускаю docker compose up, я получаю эту ошибку, когда dockerfile выполняет миграцию django.db.utils.OperationalError: (2005, "Unknown MySQL server host 'db' (-2)")
ERROR: Service 'web' failed to build: The command '/bin/sh -c python manage.py makemigrations' returned a non-zero code: 1
, вот мой Dockerfile
FROM python:3.6
ENV PYTHONUNBUFFERED 1
RUN mkdir /SFP_ingestion
WORKDIR /SFP_ingestion
COPY . /SFP_ingestion
RUN pip install -r requirements.txt
RUN python generatemodel.py
RUN python generateapp.py
RUN python manage.py makemigrations
RUN python manage.py migrate
RUN python manage.py migrate easyaudit
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
, а вот мой docker -композит. yml
services:
db:
image: mysql
restart: always
command: --default-authentication-plugin=mysql_native_password --mysqlx=0
environment:
- MYSQL_HOST=localhost
- MYSQL_PORT=3306 # cannot change this port to other number
- MYSQL_DATABASE=sfp # name you want for the database
- MYSQL_USER=root # change to whatever username you want
- MYSQL_PASSWORD=password #change to the password you want for user
- MYSQL_ROOT_PASSWORD=password #change to good root password
ports:
- "3306:3306"
expose:
- "3306"
volumes:
- "./db:/var/lib/mysql"
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/SFP_ingestion
restart: always
ports:
- "8000:8000"
depends_on:
- db